mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
29 lines
1010 B
Plaintext
29 lines
1010 B
Plaintext
controlFlowForIndexSignatures.ts(20,23): error TS2322: Type 'number' is not assignable to type 'string'.
|
|
|
|
|
|
==== controlFlowForIndexSignatures.ts (1 errors) ====
|
|
type Foo = { bar: string };
|
|
const boo: Foo = { bar: 'bar' };
|
|
|
|
function a(aboo1?: Foo) {
|
|
if (!aboo1) return;
|
|
const aboo2: { [key: string]: typeof aboo1.bar } = boo;
|
|
}
|
|
|
|
declare let b: Foo | undefined;
|
|
if (b) {
|
|
const bboo: { [key: string]: typeof b.bar } = boo;
|
|
}
|
|
b = boo;
|
|
const bboo: { [key: string]: typeof b.bar } = boo;
|
|
|
|
declare let c: string | number;
|
|
if (typeof c === 'string') {
|
|
type C = { [key: string]: typeof c };
|
|
const boo1: C = { bar: 'works' };
|
|
const boo2: C = { bar: 1 }; // should error
|
|
~~~
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
!!! related TS6501 controlFlowForIndexSignatures.ts:18:16: The expected type comes from this index signature.
|
|
}
|
|
|