mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Add regression test
This commit is contained in:
parent
cdda5dfd61
commit
2cec4c5ebb
@ -0,0 +1,32 @@
|
||||
tests/cases/compiler/keyofIsLiteralContexualType.ts(5,9): error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'.
|
||||
Type '"a" | "b" | "c"' is not assignable to type 'keyof T'.
|
||||
Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'.
|
||||
Type '"c"' is not assignable to type '"a" | "b"'.
|
||||
Type '"c"' is not assignable to type 'keyof T'.
|
||||
Type '"c"' is not assignable to type '"a" | "b"'.
|
||||
tests/cases/compiler/keyofIsLiteralContexualType.ts(13,11): error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/keyofIsLiteralContexualType.ts (2 errors) ====
|
||||
// keyof T is a literal contextual type
|
||||
|
||||
function foo<T extends { a: string, b: string }>() {
|
||||
let a: (keyof T)[] = ["a", "b"];
|
||||
let b: (keyof T)[] = ["a", "b", "c"];
|
||||
~
|
||||
!!! error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'.
|
||||
!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type 'keyof T'.
|
||||
!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'.
|
||||
!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'.
|
||||
!!! error TS2322: Type '"c"' is not assignable to type 'keyof T'.
|
||||
!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'.
|
||||
}
|
||||
|
||||
// Repro from #12455
|
||||
|
||||
declare function pick<T, K extends keyof T>(obj: T, propNames: K[]): Pick<T, K>;
|
||||
|
||||
let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]);
|
||||
let b = x.b; // Error
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'.
|
||||
23
tests/baselines/reference/keyofIsLiteralContexualType.js
Normal file
23
tests/baselines/reference/keyofIsLiteralContexualType.js
Normal file
@ -0,0 +1,23 @@
|
||||
//// [keyofIsLiteralContexualType.ts]
|
||||
// keyof T is a literal contextual type
|
||||
|
||||
function foo<T extends { a: string, b: string }>() {
|
||||
let a: (keyof T)[] = ["a", "b"];
|
||||
let b: (keyof T)[] = ["a", "b", "c"];
|
||||
}
|
||||
|
||||
// Repro from #12455
|
||||
|
||||
declare function pick<T, K extends keyof T>(obj: T, propNames: K[]): Pick<T, K>;
|
||||
|
||||
let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]);
|
||||
let b = x.b; // Error
|
||||
|
||||
//// [keyofIsLiteralContexualType.js]
|
||||
// keyof T is a literal contextual type
|
||||
function foo() {
|
||||
var a = ["a", "b"];
|
||||
var b = ["a", "b", "c"];
|
||||
}
|
||||
var x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]);
|
||||
var b = x.b; // Error
|
||||
13
tests/cases/compiler/keyofIsLiteralContexualType.ts
Normal file
13
tests/cases/compiler/keyofIsLiteralContexualType.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// keyof T is a literal contextual type
|
||||
|
||||
function foo<T extends { a: string, b: string }>() {
|
||||
let a: (keyof T)[] = ["a", "b"];
|
||||
let b: (keyof T)[] = ["a", "b", "c"];
|
||||
}
|
||||
|
||||
// Repro from #12455
|
||||
|
||||
declare function pick<T, K extends keyof T>(obj: T, propNames: K[]): Pick<T, K>;
|
||||
|
||||
let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]);
|
||||
let b = x.b; // Error
|
||||
Loading…
x
Reference in New Issue
Block a user