Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit index signatures #7029

Merged
merged 10 commits into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 112 additions & 99 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,10 @@
"category": "Error",
"code": 2529
},
"Property '{0}' is incompatible with index signature.": {
"category": "Error",
"code": 2530
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts(15,5): error TS2322: Type '{}' is not assignable to type '{ [n: number]: Foo; }'.
Index signature is missing in type '{}'.
tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts(19,5): error TS2322: Type '() => void' is not assignable to type '{ [n: number]: Bar; }'.
Index signature is missing in type '() => void'.


==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ====
==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (1 errors) ====
interface Foo { a }
interface Bar { b }

Expand All @@ -20,9 +18,6 @@ tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignatur
var f = () => { };

var v1: {
~~
!!! error TS2322: Type '{}' is not assignable to type '{ [n: number]: Foo; }'.
!!! error TS2322: Index signature is missing in type '{}'.
[n: number]: Foo
} = o; // Should be allowed

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/badOverloadError.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ function method() {
>dictionary : { [index: string]: string; }
><{ [index: string]: string; }>{} : { [index: string]: string; }
>index : string
>{} : { [x: string]: undefined; }
>{} : {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var obj: { [s: string]: Contextual } = { s: e }; // { s: Ellement; [s: string]:
>obj : { [s: string]: Contextual; }
>s : string
>Contextual : Contextual
>{ s: e } : { [x: string]: Ellement; s: Ellement; }
>{ s: e } : { s: Ellement; }
>s : Ellement
>e : Ellement

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ x2 += E.a;
x2 += {};
>x2 += {} : string
>x2 : string
>{} : { [x: number]: undefined; }
>{} : {}

x2 += null;
>x2 += null : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames10_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var a: any;
>a : any

var v = {
>v : { [0](): void; [""](): void; }
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [0](): void; [""](): void; }
>v : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; }
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; }

[s]() { },
>s : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames10_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var a: any;
>a : any

var v = {
>v : { [0](): void; [""](): void; }
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [0](): void; [""](): void; }
>v : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; }
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; }

[s]() { },
>s : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames11_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var a: any;
>a : any

var v = {
>v : { readonly [0]: number; [""]: any; }
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; }
>v : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; }
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; }

get [s]() { return 0; },
>s : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames11_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var a: any;
>a : any

var v = {
>v : { readonly [0]: number; [""]: any; }
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; }
>v : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; }
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; }

get [s]() { return 0; },
>s : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames18_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ function foo() {
>foo : () => void

var obj = {
>obj : {}
>{ [this.bar]: 0 } : {}
>obj : { [x: number]: number; }
>{ [this.bar]: 0 } : { [x: number]: number; }

[this.bar]: 0
>this.bar : any
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames18_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ function foo() {
>foo : () => void

var obj = {
>obj : {}
>{ [this.bar]: 0 } : {}
>obj : { [x: number]: number; }
>{ [this.bar]: 0 } : { [x: number]: number; }

[this.bar]: 0
>this.bar : any
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames1_ES5.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames1_ES5.ts ===
var v = {
>v : {}
>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : {}
>v : { [x: number]: number | string; }
>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: number | string; }

get [0 + 1]() { return 0 },
>0 + 1 : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames1_ES6.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames1_ES6.ts ===
var v = {
>v : {}
>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : {}
>v : { [x: number]: number | string; }
>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: number | string; }

get [0 + 1]() { return 0 },
>0 + 1 : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames20_ES5.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames20_ES5.ts ===
var obj = {
>obj : {}
>{ [this.bar]: 0} : {}
>obj : { [x: number]: number; }
>{ [this.bar]: 0} : { [x: number]: number; }

[this.bar]: 0
>this.bar : any
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames20_ES6.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames20_ES6.ts ===
var obj = {
>obj : {}
>{ [this.bar]: 0} : {}
>obj : { [x: number]: number; }
>{ [this.bar]: 0} : { [x: number]: number; }

[this.bar]: 0
>this.bar : any
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames22_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class C {
>bar : () => number

var obj = {
>obj : {}
>{ [this.bar()]() { } } : {}
>obj : { [x: number]: () => void; }
>{ [this.bar()]() { } } : { [x: number]: () => void; }

[this.bar()]() { }
>this.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames22_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class C {
>bar : () => number

var obj = {
>obj : {}
>{ [this.bar()]() { } } : {}
>obj : { [x: number]: () => void; }
>{ [this.bar()]() { } } : { [x: number]: () => void; }

[this.bar()]() { }
>this.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames25_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class C extends Base {
>foo : () => number

var obj = {
>obj : {}
>{ [super.bar()]() { } } : {}
>obj : { [x: number]: () => void; }
>{ [super.bar()]() { } } : { [x: number]: () => void; }

[super.bar()]() { }
>super.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames25_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class C extends Base {
>foo : () => number

var obj = {
>obj : {}
>{ [super.bar()]() { } } : {}
>obj : { [x: number]: () => void; }
>{ [super.bar()]() { } } : { [x: number]: () => void; }

[super.bar()]() { }
>super.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames28_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class C extends Base {
>super : typeof Base

var obj = {
>obj : {}
>{ [(super(), "prop")]() { } } : {}
>obj : { [x: string]: () => void; }
>{ [(super(), "prop")]() { } } : { [x: string]: () => void; }

[(super(), "prop")]() { }
>(super(), "prop") : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames28_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class C extends Base {
>super : typeof Base

var obj = {
>obj : {}
>{ [(super(), "prop")]() { } } : {}
>obj : { [x: string]: () => void; }
>{ [(super(), "prop")]() { } } : { [x: string]: () => void; }

[(super(), "prop")]() { }
>(super(), "prop") : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames29_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class C {
>() => { var obj = { [this.bar()]() { } // needs capture }; } : () => void

var obj = {
>obj : {}
>{ [this.bar()]() { } // needs capture } : {}
>obj : { [x: number]: () => void; }
>{ [this.bar()]() { } // needs capture } : { [x: number]: () => void; }

[this.bar()]() { } // needs capture
>this.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames29_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class C {
>() => { var obj = { [this.bar()]() { } // needs capture }; } : () => void

var obj = {
>obj : {}
>{ [this.bar()]() { } // needs capture } : {}
>obj : { [x: number]: () => void; }
>{ [this.bar()]() { } // needs capture } : { [x: number]: () => void; }

[this.bar()]() { } // needs capture
>this.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames31_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class C extends Base {
>() => { var obj = { [super.bar()]() { } // needs capture }; } : () => void

var obj = {
>obj : {}
>{ [super.bar()]() { } // needs capture } : {}
>obj : { [x: number]: () => void; }
>{ [super.bar()]() { } // needs capture } : { [x: number]: () => void; }

[super.bar()]() { } // needs capture
>super.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames31_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class C extends Base {
>() => { var obj = { [super.bar()]() { } // needs capture }; } : () => void

var obj = {
>obj : {}
>{ [super.bar()]() { } // needs capture } : {}
>obj : { [x: number]: () => void; }
>{ [super.bar()]() { } // needs capture } : { [x: number]: () => void; }

[super.bar()]() { } // needs capture
>super.bar() : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames33_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class C<T> {
>bar : () => number

var obj = {
>obj : {}
>{ [foo<T>()]() { } } : {}
>obj : { [x: string]: () => void; }
>{ [foo<T>()]() { } } : { [x: string]: () => void; }

[foo<T>()]() { }
>foo<T>() : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames33_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class C<T> {
>bar : () => number

var obj = {
>obj : {}
>{ [foo<T>()]() { } } : {}
>obj : { [x: string]: () => void; }
>{ [foo<T>()]() { } } : { [x: string]: () => void; }

[foo<T>()]() { }
>foo<T>() : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames46_ES5.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames46_ES5.ts ===
var o = {
>o : {}
>{ ["" || 0]: 0} : {}
>o : { [x: string]: number; }
>{ ["" || 0]: 0} : { [x: string]: number; }

["" || 0]: 0
>"" || 0 : string | number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames46_ES6.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames46_ES6.ts ===
var o = {
>o : {}
>{ ["" || 0]: 0} : {}
>o : { [x: string]: number; }
>{ ["" || 0]: 0} : { [x: string]: number; }

["" || 0]: 0
>"" || 0 : string | number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames47_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ enum E2 { x }
>x : E2

var o = {
>o : {}
>{ [E1.x || E2.x]: 0} : {}
>o : { [x: number]: number; }
>{ [E1.x || E2.x]: 0} : { [x: number]: number; }

[E1.x || E2.x]: 0
>E1.x || E2.x : E1 | E2
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames47_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ enum E2 { x }
>x : E2

var o = {
>o : {}
>{ [E1.x || E2.x]: 0} : {}
>o : { [x: number]: number; }
>{ [E1.x || E2.x]: 0} : { [x: number]: number; }

[E1.x || E2.x]: 0
>E1.x || E2.x : E1 | E2
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames48_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ extractIndexer({
}); // Should return string

extractIndexer({
>extractIndexer({ ["" || 0]: ""}) : any
>extractIndexer({ ["" || 0]: ""}) : string
>extractIndexer : <T>(p: { [n: number]: T; }) => T
>{ ["" || 0]: ""} : { [x: number]: undefined; }
>{ ["" || 0]: ""} : { [x: string]: string; }

["" || 0]: ""
>"" || 0 : string | number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames48_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ extractIndexer({
}); // Should return string

extractIndexer({
>extractIndexer({ ["" || 0]: ""}) : any
>extractIndexer({ ["" || 0]: ""}) : string
>extractIndexer : <T>(p: { [n: number]: T; }) => T
>{ ["" || 0]: ""} : { [x: number]: undefined; }
>{ ["" || 0]: ""} : { [x: string]: string; }

["" || 0]: ""
>"" || 0 : string | number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames4_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var a: any;
>a : any

var v = {
>v : { [0]: number; [""]: number; }
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [0]: number; [""]: number; }
>v : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; }
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; }

[s]: 0,
>s : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames4_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var a: any;
>a : any

var v = {
>v : { [0]: number; [""]: number; }
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [0]: number; [""]: number; }
>v : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; }
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; }

[s]: 0,
>s : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/computedPropertyNames7_ES5.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ enum E {
>member : E
}
var v = {
>v : {}
>{ [E.member]: 0} : {}
>v : { [x: number]: number; }
>{ [E.member]: 0} : { [x: number]: number; }

[E.member]: 0
>E.member : E
Expand Down
Loading