TypeScript/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt

57 lines
1.7 KiB
Plaintext

==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts (7 errors) ====
// String indexer providing a constraint of a user defined type
class A {
foo(): string { return ''; }
}
class B extends A {
bar(): string { return ''; }
}
class Foo {
[x: string]: A;
a: A; // ok
b: B; // ok
c: number; // error
~~~~~~~~~~
!!! Property 'c' of type 'number' is not assignable to string index type 'A'.
d: string; // error
~~~~~~~~~~
!!! Property 'd' of type 'string' is not assignable to string index type 'A'.
}
interface Foo2 {
[x: string]: A;
a: A; // ok
b: B; // ok
c: number; // error
~~~~~~~~~~
!!! Property 'c' of type 'number' is not assignable to string index type 'A'.
d: string; // error
~~~~~~~~~~
!!! Property 'd' of type 'string' is not assignable to string index type 'A'.
}
var a: {
[x: string]: A;
a: A; // ok
b: B; // ok
c: number; // error
~~~~~~~~~~
!!! Property 'c' of type 'number' is not assignable to string index type 'A'.
d: string; // error
~~~~~~~~~~
!!! Property 'd' of type 'string' is not assignable to string index type 'A'.
};
// error
var b: { [x: string]: A } = {
~
!!! Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }':
!!! Index signatures are incompatible:
!!! Type 'typeof A' is not assignable to type 'A':
!!! Property 'foo' is missing in type 'typeof A'.
a: A,
b: B
}