Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

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 Apr 6, 2021
2 parents dd51fd9 + a1b2bdd commit 22256e2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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 22256e2

Please sign in to comment.