-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement property access about non-primitive constraints of IAT (
#1067) **Description:** ```ts function l<T extends {}, P extends keyof T>(s: string, tp: T[P]): void { tp = s; } function m<T extends { a: number }, P extends keyof T>(s: string, tp: T[P]): void { tp = s; } function f<T extends object, P extends keyof T>(s: string, tp: T[P]): void { tp = s; } ```
- Loading branch information
1 parent
f46b724
commit a354f07
Showing
19 changed files
with
268 additions
and
48 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
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
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
19 changes: 19 additions & 0 deletions
19
crates/stc_ts_file_analyzer/tests/pass-only/types/keyof/3.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,19 @@ | ||
// @strictNullChecks: true | ||
// @declaration: true | ||
|
||
class Shape { | ||
name: string; | ||
width: number; | ||
height: number; | ||
visible: boolean; | ||
} | ||
|
||
function getProperty<T, K extends keyof T>(obj: T, key: K) { | ||
return obj[key]; | ||
} | ||
|
||
function f33<S extends Shape, K extends keyof S>(shape: S, key: K) { | ||
let name = getProperty(shape, "name"); | ||
let prop = getProperty(shape, key); | ||
return prop; | ||
} |
6 changes: 6 additions & 0 deletions
6
crates/stc_ts_file_analyzer/tests/pass-only/types/mapped/.1.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,6 @@ | ||
// @strictNullChecks: true | ||
// @declaration: true | ||
|
||
function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K) { | ||
x[k] = y[k]; | ||
} |
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,23 @@ | ||
// @strictNullChecks: true | ||
// @declaration: true | ||
|
||
function f1<T>(x: T, k: keyof T) { | ||
return x[k]; | ||
} | ||
|
||
function f2<T, K extends keyof T>(x: T, k: K) { | ||
return x[k]; | ||
} | ||
|
||
function f3<T, U extends T>(x: T, y: U, k: keyof T) { | ||
x[k] = y[k]; | ||
} | ||
|
||
function f10<T>(x: T, y: Partial<T>, k: keyof T) { | ||
y[k] = x[k]; | ||
} | ||
|
||
function f12<T, U extends T>(x: T, y: Partial<U>, k: keyof T) { | ||
x[k] = y[k]; // Error | ||
y[k] = x[k]; // Error | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/stc_ts_file_analyzer/tests/tsc/types/mapped/1.tsc-errors.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,14 @@ | ||
[ | ||
{ | ||
"file": "tests/tsc/types/mapped/1.ts", | ||
"line": 21, | ||
"col": 5, | ||
"code": 2322 | ||
}, | ||
{ | ||
"file": "tests/tsc/types/mapped/1.ts", | ||
"line": 22, | ||
"col": 5, | ||
"code": 2322 | ||
} | ||
] |
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,7 @@ | ||
// @strictNullChecks: true | ||
// @declaration: true | ||
|
||
function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K) { | ||
x[k] = y[k]; // Error | ||
y[k] = x[k]; // Error | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/stc_ts_file_analyzer/tests/tsc/types/mapped/2.tsc-errors.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,14 @@ | ||
[ | ||
{ | ||
"file": "tests/tsc/types/mapped/2.ts", | ||
"line": 5, | ||
"col": 5, | ||
"code": 2536 | ||
}, | ||
{ | ||
"file": "tests/tsc/types/mapped/2.ts", | ||
"line": 6, | ||
"col": 12, | ||
"code": 2536 | ||
} | ||
] |
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
20 changes: 20 additions & 0 deletions
20
crates/stc_ts_file_analyzer/tests/tsc/types/nonPrimitive/1.tsc-errors.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 @@ | ||
[ | ||
{ | ||
"file": "tests/tsc/types/nonPrimitive/1.ts", | ||
"line": 5, | ||
"col": 5, | ||
"code": 2322 | ||
}, | ||
{ | ||
"file": "tests/tsc/types/nonPrimitive/1.ts", | ||
"line": 8, | ||
"col": 5, | ||
"code": 2322 | ||
}, | ||
{ | ||
"file": "tests/tsc/types/nonPrimitive/1.ts", | ||
"line": 11, | ||
"col": 5, | ||
"code": 2322 | ||
} | ||
] |
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
Oops, something went wrong.