2014-07-13 01:04:16 +02:00
|
|
|
==== 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 } = {
|
2014-07-19 02:30:06 +02:00
|
|
|
~
|
2014-07-13 01:04:16 +02:00
|
|
|
!!! 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':
|
2014-07-19 02:30:06 +02:00
|
|
|
!!! Property 'foo' is missing in type 'typeof A'.
|
|
|
|
a: A,
|
|
|
|
b: B
|
|
|
|
}
|