* Prefer a likely literal over anonymous type in --noImplicitAny codefixes
Before trying to make an anonymous type for a type's usage, we'll first check if there is exactly one builtin primitive the usage is assignable to, and use it if so. Right now that's only `number` and `string` because `boolean` has no distinguishable members.
A couple of implementation details:
* `tryInsertTypeAnnotation` needed to know to insert a type _after_ a node's `exclamationToken` if it exists
* This code area was written before `??` 😉
* Used unknown/any instead of void when applicable
* Fix little whitespace change in tests/cases/fourslash/codeFixInferFromUsagePropertyAccessJS.ts
* Undid some now-unnecessary unknown additions
* Took advice on restricting void to just call expressions
10 lines
270 B
TypeScript
10 lines
270 B
TypeScript
/// <reference path='fourslash.ts' />
|
|
|
|
// @noImplicitAny: true
|
|
//// let [|text! |];
|
|
//// text.length;
|
|
//// text.indexOf("z");
|
|
//// text.charAt(0);
|
|
|
|
verify.rangeAfterCodeFix("text!: string", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0);
|