TypeScript/tests/cases/fourslash/typeToStringCrashInCodeFix.ts
Nathan Shively-Sanders 9658b476c2
Fix inferFromUsage on index signatures (#25934)
* Fix inferFromUsage on index signatures

1. Check the argumentExpression to determine the index signature type.
Previously, the code mistakenly checked the type of the element access
itself, which never returned a good type.
2. If inference for the index signature type fails, substitute anyType.
Previously, the code would create a bad index signature with an
undefined type.
3. Add tests. Previously, there were no tests.

* Fixing (1) means that number index signatures are now created.
Previously, only string index signatures would be created.
* Fixing (2) means that index signatures will be inferred from single
usage like `return a[0]`. Previously, the refactoring would fail,
perhaps because of a check when stringifying the index signature (I
haven't tracked down why.)

* Update fourslash test with improved inference
2018-07-25 10:51:11 -07:00

7 lines
220 B
TypeScript

/// <reference path="fourslash.ts" />
// @noImplicitAny: true
//// function f([|y |], z = { p: y[
verify.rangeAfterCodeFix("y: { [x: string]: any; }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0);