mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
61 lines
1.0 KiB
TypeScript
61 lines
1.0 KiB
TypeScript
//// [tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts] ////
|
|
|
|
//// [stringIndexerConstrainsPropertyDeclarations2.ts]
|
|
// 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
|
|
d: string; // error
|
|
}
|
|
|
|
interface Foo2 {
|
|
[x: string]: A;
|
|
a: A; // ok
|
|
b: B; // ok
|
|
c: number; // error
|
|
d: string; // error
|
|
}
|
|
|
|
var a: {
|
|
[x: string]: A;
|
|
a: A; // ok
|
|
b: B; // ok
|
|
c: number; // error
|
|
d: string; // error
|
|
};
|
|
|
|
// error
|
|
var b: { [x: string]: A } = {
|
|
a: A,
|
|
b: B
|
|
}
|
|
|
|
//// [stringIndexerConstrainsPropertyDeclarations2.js]
|
|
"use strict";
|
|
// String indexer providing a constraint of a user defined type
|
|
class A {
|
|
foo() { return ''; }
|
|
}
|
|
class B extends A {
|
|
bar() { return ''; }
|
|
}
|
|
class Foo {
|
|
}
|
|
var a;
|
|
// error
|
|
var b = {
|
|
a: A,
|
|
b: B
|
|
};
|