mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
43 lines
1.6 KiB
Plaintext
43 lines
1.6 KiB
Plaintext
extractInferenceImprovement.ts(26,26): error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type 'never'.
|
|
extractInferenceImprovement.ts(28,1): error TS2322: Type 'string | number' is not assignable to type 'string'.
|
|
Type 'number' is not assignable to type 'string'.
|
|
extractInferenceImprovement.ts(28,26): error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type '"first" | "second"'.
|
|
|
|
|
|
==== extractInferenceImprovement.ts (3 errors) ====
|
|
// repro mostly from https://github.com/Microsoft/TypeScript/issues/25065
|
|
function getProperty2<T, K extends keyof T>(obj: T, key: Extract<K, string>): T[K] {
|
|
return obj[key];
|
|
}
|
|
|
|
function getProperty3<T, K extends Extract<keyof T, string>>(obj: T, key: K): T[K] {
|
|
return obj[key];
|
|
}
|
|
|
|
const s = Symbol();
|
|
interface StrNum {
|
|
first: string;
|
|
second: number;
|
|
[s]: string;
|
|
}
|
|
const obj: StrNum = {} as any;
|
|
|
|
let prop: string;
|
|
|
|
// should work
|
|
prop = getProperty2(obj, 'first');
|
|
|
|
prop = getProperty3(obj, 'first');
|
|
|
|
// Should fail
|
|
prop = getProperty2(obj, s);
|
|
~
|
|
!!! error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type 'never'.
|
|
|
|
prop = getProperty3(obj, s);
|
|
~~~~
|
|
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
~
|
|
!!! error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type '"first" | "second"'.
|
|
|