Skip to content

Commit

Permalink
Merge pull request #317 from jablko/patch-7
Browse files Browse the repository at this point in the history
Copy advice from the DT common mistakes
  • Loading branch information
Orta Therox authored and sandersn committed Nov 29, 2021
1 parent 817d29d commit 1839953
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/dtslint/docs/no-unnecessary-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ function clear(array: any[]): void;

---

`getMeAT<T>(): T`:
If a type parameter does not appear in the types of any parameters, you don't really have a generic function, you just have a disguised type assertion.
Prefer to use a real type assertion, e.g. `getMeAT() as number`.
Example where a type parameter is acceptable: `function id<T>(value: T): T;`.
Example where it is not acceptable: `function parseJson<T>(json: string): T;`.
Exception: `new Map<string, number>()` is OK.

**Bad**:

```ts
Expand Down

0 comments on commit 1839953

Please sign in to comment.