Skip to content

Commit

Permalink
no-misused-generics: add test with this parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff committed Apr 26, 2018
1 parent 5a22eed commit f22efda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ function doStuff<K, V>(map: Map<K, V>, key: K) {
map.set(key, v);
return v; // signature has implicit return type `V`, but we cannot know that without type information
}

declare class Foo {
prop: string;
getProp<T>(this: Record<'prop', T>): T;
compare<T>(this: Record<'prop', T>, other: Record<'prop', T>): number;
foo<T>(this: T): void;
~ [error no-misused-generics: TypeParameter 'T' is not used to enforce a constraint between types and can be replaced with 'any'.]
}
7 changes: 7 additions & 0 deletions packages/mimir/test/no-misused-generics/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ function doStuff<K, V>(map: Map<K, V>, key: K) {
map.set(key, v);
return v; // signature has implicit return type `V`, but we cannot know that without type information
}

declare class Foo {
prop: string;
getProp<T>(this: Record<'prop', T>): T;
compare<T>(this: Record<'prop', T>, other: Record<'prop', T>): number;
foo<T>(this: T): void;
}

0 comments on commit f22efda

Please sign in to comment.