Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for noImplicitAny indexing on Object
- Loading branch information
Showing
5 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
35 changes: 32 additions & 3 deletions
35
tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(1,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. | ||
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(8,1): error TS7042: Element implicitly has an 'any' type because type '{ get: (key: string) => string; }' has no index signature. Did you mean to call 'c.get' ? | ||
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(14,1): error TS7042: Element implicitly has an 'any' type because type '{ set: (key: string) => string; }' has no index signature. Did you mean to call 'd.set' ? | ||
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(21,1): error TS7042: Element implicitly has an 'any' type because type '{ set: (key: string) => string; get: (key: string) => string; }' has no index signature. Did you mean to call 'e.get or e.set' ? | ||
|
||
|
||
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (1 errors) ==== | ||
var x = {}["hello"]; | ||
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (4 errors) ==== | ||
var a = {}["hello"]; | ||
~~~~~~~~~~~ | ||
!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. | ||
var y: string = { '': 'foo' }['']; | ||
var b: string = { '': 'foo' }['']; | ||
|
||
// Should give suggestion 'c.get' | ||
var c = { | ||
get: (key: string) => 'foobar' | ||
}; | ||
c['hello']; | ||
~~~~~~~~~~ | ||
!!! error TS7042: Element implicitly has an 'any' type because type '{ get: (key: string) => string; }' has no index signature. Did you mean to call 'c.get' ? | ||
|
||
// Should give suggestion 'd.set' | ||
var d = { | ||
set: (key: string) => 'foobar' | ||
}; | ||
d['hello']; | ||
~~~~~~~~~~ | ||
!!! error TS7042: Element implicitly has an 'any' type because type '{ set: (key: string) => string; }' has no index signature. Did you mean to call 'd.set' ? | ||
|
||
// Should give suggestion 'e.get or e.set' | ||
var e = { | ||
set: (key: string) => 'foobar', | ||
get: (key: string) => 'foobar' | ||
}; | ||
e['hello']; | ||
~~~~~~~~~~ | ||
!!! error TS7042: Element implicitly has an 'any' type because type '{ set: (key: string) => string; get: (key: string) => string; }' has no index signature. Did you mean to call 'e.get or e.set' ? | ||
|
44 changes: 40 additions & 4 deletions
44
tests/baselines/reference/noImplicitAnyStringIndexerOnObject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
//// [noImplicitAnyStringIndexerOnObject.ts] | ||
var x = {}["hello"]; | ||
var y: string = { '': 'foo' }['']; | ||
var a = {}["hello"]; | ||
var b: string = { '': 'foo' }['']; | ||
|
||
// Should give suggestion 'c.get' | ||
var c = { | ||
get: (key: string) => 'foobar' | ||
}; | ||
c['hello']; | ||
|
||
// Should give suggestion 'd.set' | ||
var d = { | ||
set: (key: string) => 'foobar' | ||
}; | ||
d['hello']; | ||
|
||
// Should give suggestion 'e.get or e.set' | ||
var e = { | ||
set: (key: string) => 'foobar', | ||
get: (key: string) => 'foobar' | ||
}; | ||
e['hello']; | ||
|
||
|
||
//// [noImplicitAnyStringIndexerOnObject.js] | ||
var x = {}["hello"]; | ||
var y = { '': 'foo' }['']; | ||
var a = {}["hello"]; | ||
var b = { '': 'foo' }['']; | ||
// Should give suggestion 'c.get' | ||
var c = { | ||
get: function (key) { return 'foobar'; } | ||
}; | ||
c['hello']; | ||
// Should give suggestion 'd.set' | ||
var d = { | ||
set: function (key) { return 'foobar'; } | ||
}; | ||
d['hello']; | ||
// Should give suggestion 'e.get or e.set' | ||
var e = { | ||
set: function (key) { return 'foobar'; }, | ||
get: function (key) { return 'foobar'; } | ||
}; | ||
e['hello']; |
48 changes: 44 additions & 4 deletions
48
tests/baselines/reference/noImplicitAnyStringIndexerOnObject.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
=== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts === | ||
var x = {}["hello"]; | ||
>x : Symbol(x, Decl(noImplicitAnyStringIndexerOnObject.ts, 0, 3)) | ||
var a = {}["hello"]; | ||
>a : Symbol(a, Decl(noImplicitAnyStringIndexerOnObject.ts, 0, 3)) | ||
|
||
var y: string = { '': 'foo' }['']; | ||
>y : Symbol(y, Decl(noImplicitAnyStringIndexerOnObject.ts, 1, 3)) | ||
var b: string = { '': 'foo' }['']; | ||
>b : Symbol(b, Decl(noImplicitAnyStringIndexerOnObject.ts, 1, 3)) | ||
>'' : Symbol('', Decl(noImplicitAnyStringIndexerOnObject.ts, 1, 17)) | ||
>'' : Symbol('', Decl(noImplicitAnyStringIndexerOnObject.ts, 1, 17)) | ||
|
||
// Should give suggestion 'c.get' | ||
var c = { | ||
>c : Symbol(c, Decl(noImplicitAnyStringIndexerOnObject.ts, 4, 3)) | ||
|
||
get: (key: string) => 'foobar' | ||
>get : Symbol(get, Decl(noImplicitAnyStringIndexerOnObject.ts, 4, 9)) | ||
>key : Symbol(key, Decl(noImplicitAnyStringIndexerOnObject.ts, 5, 8)) | ||
|
||
}; | ||
c['hello']; | ||
>c : Symbol(c, Decl(noImplicitAnyStringIndexerOnObject.ts, 4, 3)) | ||
|
||
// Should give suggestion 'd.set' | ||
var d = { | ||
>d : Symbol(d, Decl(noImplicitAnyStringIndexerOnObject.ts, 10, 3)) | ||
|
||
set: (key: string) => 'foobar' | ||
>set : Symbol(set, Decl(noImplicitAnyStringIndexerOnObject.ts, 10, 9)) | ||
>key : Symbol(key, Decl(noImplicitAnyStringIndexerOnObject.ts, 11, 8)) | ||
|
||
}; | ||
d['hello']; | ||
>d : Symbol(d, Decl(noImplicitAnyStringIndexerOnObject.ts, 10, 3)) | ||
|
||
// Should give suggestion 'e.get or e.set' | ||
var e = { | ||
>e : Symbol(e, Decl(noImplicitAnyStringIndexerOnObject.ts, 16, 3)) | ||
|
||
set: (key: string) => 'foobar', | ||
>set : Symbol(set, Decl(noImplicitAnyStringIndexerOnObject.ts, 16, 9)) | ||
>key : Symbol(key, Decl(noImplicitAnyStringIndexerOnObject.ts, 17, 8)) | ||
|
||
get: (key: string) => 'foobar' | ||
>get : Symbol(get, Decl(noImplicitAnyStringIndexerOnObject.ts, 17, 33)) | ||
>key : Symbol(key, Decl(noImplicitAnyStringIndexerOnObject.ts, 18, 8)) | ||
|
||
}; | ||
e['hello']; | ||
>e : Symbol(e, Decl(noImplicitAnyStringIndexerOnObject.ts, 16, 3)) | ||
|
65 changes: 61 additions & 4 deletions
65
tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,72 @@ | ||
=== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts === | ||
var x = {}["hello"]; | ||
>x : any | ||
var a = {}["hello"]; | ||
>a : any | ||
>{}["hello"] : any | ||
>{} : {} | ||
>"hello" : "hello" | ||
|
||
var y: string = { '': 'foo' }['']; | ||
>y : string | ||
var b: string = { '': 'foo' }['']; | ||
>b : string | ||
>{ '': 'foo' }[''] : string | ||
>{ '': 'foo' } : { '': string; } | ||
>'' : string | ||
>'foo' : "foo" | ||
>'' : "" | ||
|
||
// Should give suggestion 'c.get' | ||
var c = { | ||
>c : { get: (key: string) => string; } | ||
>{ get: (key: string) => 'foobar'} : { get: (key: string) => string; } | ||
|
||
get: (key: string) => 'foobar' | ||
>get : (key: string) => string | ||
>(key: string) => 'foobar' : (key: string) => string | ||
>key : string | ||
>'foobar' : "foobar" | ||
|
||
}; | ||
c['hello']; | ||
>c['hello'] : any | ||
>c : { get: (key: string) => string; } | ||
>'hello' : "hello" | ||
|
||
// Should give suggestion 'd.set' | ||
var d = { | ||
>d : { set: (key: string) => string; } | ||
>{ set: (key: string) => 'foobar'} : { set: (key: string) => string; } | ||
|
||
set: (key: string) => 'foobar' | ||
>set : (key: string) => string | ||
>(key: string) => 'foobar' : (key: string) => string | ||
>key : string | ||
>'foobar' : "foobar" | ||
|
||
}; | ||
d['hello']; | ||
>d['hello'] : any | ||
>d : { set: (key: string) => string; } | ||
>'hello' : "hello" | ||
|
||
// Should give suggestion 'e.get or e.set' | ||
var e = { | ||
>e : { set: (key: string) => string; get: (key: string) => string; } | ||
>{ set: (key: string) => 'foobar', get: (key: string) => 'foobar'} : { set: (key: string) => string; get: (key: string) => string; } | ||
|
||
set: (key: string) => 'foobar', | ||
>set : (key: string) => string | ||
>(key: string) => 'foobar' : (key: string) => string | ||
>key : string | ||
>'foobar' : "foobar" | ||
|
||
get: (key: string) => 'foobar' | ||
>get : (key: string) => string | ||
>(key: string) => 'foobar' : (key: string) => string | ||
>key : string | ||
>'foobar' : "foobar" | ||
|
||
}; | ||
e['hello']; | ||
>e['hello'] : any | ||
>e : { set: (key: string) => string; get: (key: string) => string; } | ||
>'hello' : "hello" | ||
|
23 changes: 21 additions & 2 deletions
23
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
// @noimplicitany: true | ||
|
||
var x = {}["hello"]; | ||
var y: string = { '': 'foo' }['']; | ||
var a = {}["hello"]; | ||
var b: string = { '': 'foo' }['']; | ||
|
||
// Should give suggestion 'c.get' | ||
var c = { | ||
get: (key: string) => 'foobar' | ||
}; | ||
c['hello']; | ||
|
||
// Should give suggestion 'd.set' | ||
var d = { | ||
set: (key: string) => 'foobar' | ||
}; | ||
d['hello']; | ||
|
||
// Should give suggestion 'e.get or e.set' | ||
var e = { | ||
set: (key: string) => 'foobar', | ||
get: (key: string) => 'foobar' | ||
}; | ||
e['hello']; |