Skip to content

Commit

Permalink
add extra test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Nov 30, 2024
1 parent 04976bf commit 2f2b500
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ keyRemappingKeyofResult.ts(90,3): error TS2322: Type 'string' is not assignable
~
!!! error TS2322: Type 'string' is not assignable to type 'keyof { [P in keyof T as T[P] extends string ? P : never]: any; }'.
!!! error TS2322: Type 'string' is not assignable to type 'T[P] extends string ? P : never'.
const f: string = z; // error
}

export {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type StringKeys2<T> = keyof {

function h<T>(z: StringKeys2<T>) {
z = "foo"; // error
const f: string = z; // error
}

export {};
Expand Down Expand Up @@ -127,5 +128,6 @@ function test_57827(z) {
}
function h(z) {
z = "foo"; // error
const f = z; // error
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ function h<T>(z: StringKeys2<T>) {
>T : Symbol(T, Decl(keyRemappingKeyofResult.ts, 88, 11))

z = "foo"; // error
>z : Symbol(z, Decl(keyRemappingKeyofResult.ts, 88, 14))

const f: string = z; // error
>f : Symbol(f, Decl(keyRemappingKeyofResult.ts, 90, 7))
>z : Symbol(z, Decl(keyRemappingKeyofResult.ts, 88, 14))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ function h<T>(z: StringKeys2<T>) {
> : ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"foo" : "foo"
> : ^^^^^

const f: string = z; // error
>f : string
> : ^^^^^^
>z : string
> : ^^^^^^
}

export {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ keyRemappingKeyofResult.ts(90,3): error TS2322: Type 'string' is not assignable
~
!!! error TS2322: Type 'string' is not assignable to type 'keyof { [P in keyof T as T[P] extends string ? P : never]: any; }'.
!!! error TS2322: Type 'string' is not assignable to type 'T[P] extends string ? P : never'.
const f: string = z; // error
}

export {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type StringKeys2<T> = keyof {

function h<T>(z: StringKeys2<T>) {
z = "foo"; // error
const f: string = z; // error
}

export {};
Expand Down Expand Up @@ -127,5 +128,6 @@ function test_57827(z) {
}
function h(z) {
z = "foo"; // error
const f = z; // error
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ function h<T>(z: StringKeys2<T>) {
>T : Symbol(T, Decl(keyRemappingKeyofResult.ts, 88, 11))

z = "foo"; // error
>z : Symbol(z, Decl(keyRemappingKeyofResult.ts, 88, 14))

const f: string = z; // error
>f : Symbol(f, Decl(keyRemappingKeyofResult.ts, 90, 7))
>z : Symbol(z, Decl(keyRemappingKeyofResult.ts, 88, 14))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ function h<T>(z: StringKeys2<T>) {
> : ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>"foo" : "foo"
> : ^^^^^

const f: string = z; // error
>f : string
> : ^^^^^^
>z : string
> : ^^^^^^
}

export {};
Expand Down
1 change: 1 addition & 0 deletions tests/cases/compiler/keyRemappingKeyofResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type StringKeys2<T> = keyof {

function h<T>(z: StringKeys2<T>) {
z = "foo"; // error
const f: string = z; // ok
}

export {};

0 comments on commit 2f2b500

Please sign in to comment.