-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ts-expect-error for specific version ranges (#1021)
- Loading branch information
1 parent
d2269e7
commit 8100279
Showing
11 changed files
with
243 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@definitelytyped/eslint-plugin": patch | ||
--- | ||
|
||
Support ts-expect-error for specific version ranges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...-plugin/test/__file_snapshots__/types/expect-error-range/expect-error-range-tests.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
types/expect-error-range/expect-error-range-tests.ts | ||
8:11 error [email protected] compile error: | ||
Type 'string | undefined' is not assignable to type 'string'. | ||
Type 'undefined' is not assignable to type 'string' @definitelytyped/expect | ||
11:11 error [email protected] compile error: | ||
Type 'string' is not assignable to type 'never' @definitelytyped/expect | ||
16:5 error [email protected] compile error: | ||
Unused '@ts-expect-error' directive @definitelytyped/expect | ||
20:5 error [email protected] compile error: | ||
Unused '@ts-expect-error' directive @definitelytyped/expect | ||
27:5 error [email protected] compile error: | ||
Unused '@ts-expect-error' directive @definitelytyped/expect | ||
31:5 error [email protected] compile error: | ||
Unused '@ts-expect-error' directive @definitelytyped/expect | ||
|
||
✖ 6 problems (6 errors, 0 warnings) | ||
|
||
==== types/expect-error-range/expect-error-range-tests.ts ==== | ||
|
||
// In TypeScript <5.5, elem will have type "string", | ||
// but 5.5 it will be "string | undefined". | ||
const elem = ["value", undefined].filter(x => x != null)[0]; | ||
|
||
|
||
{ | ||
// This should error in 5.4, but not 5.5. | ||
const test1: string = elem; | ||
~~~~~ | ||
!!! @definitelytyped/expect: [email protected] compile error: | ||
!!! : Type 'string | undefined' is not assignable to type 'string'. | ||
!!! : Type 'undefined' is not assignable to type 'string'. | ||
|
||
// This should error in 5.5, but not 5.4. | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
~~~~~ | ||
!!! @definitelytyped/expect: [email protected] compile error: | ||
!!! : Type 'string' is not assignable to type 'never'. | ||
} | ||
|
||
{ | ||
// This should error in 5.5, but not 5.4. | ||
// @ts-expect-error | ||
~~~~~~~~~~~~~~~~~~~ | ||
!!! @definitelytyped/expect: [email protected] compile error: | ||
!!! : Unused '@ts-expect-error' directive. | ||
const test1: string = elem; | ||
|
||
// This should error in 5.4, but not 5.5. | ||
// @ts-expect-error | ||
~~~~~~~~~~~~~~~~~~~ | ||
!!! @definitelytyped/expect: [email protected] compile error: | ||
!!! : Unused '@ts-expect-error' directive. | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} | ||
|
||
// These should be treated as though there is no range. | ||
{ | ||
// This should error in 5.5, but not 5.4. | ||
// @ts-expect-error random non-range text | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! @definitelytyped/expect: [email protected] compile error: | ||
!!! : Unused '@ts-expect-error' directive. | ||
const test1: string = elem; | ||
|
||
// This should error in 5.4, but not 5.5. | ||
// @ts-expect-error random non-range text | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! @definitelytyped/expect: [email protected] compile error: | ||
!!! : Unused '@ts-expect-error' directive. | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} | ||
|
||
// None of these expects should error. | ||
{ | ||
// @ts-expect-error <5.5 | ||
const test1: string = elem; | ||
|
||
// @ts-expect-error >=5.5 | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/eslint-plugin/test/__file_snapshots__/types/expect-error-range/index.d.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
No errors | ||
|
||
==== types/expect-error-range/index.d.ts ==== | ||
|
||
export const value: number; |
10 changes: 10 additions & 0 deletions
10
packages/eslint-plugin/test/fixtures/types/expect-error-range/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
settings: { | ||
dt: { | ||
versionsToTest: [ | ||
{ versionName: "5.4", path: "typescript-5.4" }, | ||
{ versionName: "5.5", path: "typescript-5.5" } | ||
] | ||
} | ||
}, | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/eslint-plugin/test/fixtures/types/expect-error-range/expect-error-range-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// In TypeScript <5.5, elem will have type "string", | ||
// but 5.5 it will be "string | undefined". | ||
const elem = ["value", undefined].filter(x => x != null)[0]; | ||
|
||
|
||
{ | ||
// This should error in 5.4, but not 5.5. | ||
const test1: string = elem; | ||
|
||
// This should error in 5.5, but not 5.4. | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} | ||
|
||
{ | ||
// This should error in 5.5, but not 5.4. | ||
// @ts-expect-error | ||
const test1: string = elem; | ||
|
||
// This should error in 5.4, but not 5.5. | ||
// @ts-expect-error | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} | ||
|
||
// These should be treated as though there is no range. | ||
{ | ||
// This should error in 5.5, but not 5.4. | ||
// @ts-expect-error random non-range text | ||
const test1: string = elem; | ||
|
||
// This should error in 5.4, but not 5.5. | ||
// @ts-expect-error random non-range text | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} | ||
|
||
// None of these expects should error. | ||
{ | ||
// @ts-expect-error <5.5 | ||
const test1: string = elem; | ||
|
||
// @ts-expect-error >=5.5 | ||
const test2: undefined extends typeof elem ? typeof elem : never = elem; | ||
} | ||
|
1 change: 1 addition & 0 deletions
1
packages/eslint-plugin/test/fixtures/types/expect-error-range/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value: number; |
5 changes: 5 additions & 0 deletions
5
packages/eslint-plugin/test/fixtures/types/expect-error-range/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "@types/expect-error-range", | ||
"version": "2.0.9999", | ||
"owners": [] | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/eslint-plugin/test/fixtures/types/expect-error-range/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"expect-error-range-tests.ts" | ||
] | ||
} |
Oops, something went wrong.