* 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
39 lines
691 B
TypeScript
39 lines
691 B
TypeScript
/// <reference path='fourslash.ts' />
|
|
|
|
// @allowJs: true
|
|
// @checkJs: true
|
|
// @noImplicitAny: true
|
|
// @Filename: important.js
|
|
|
|
////function foo([|a, m, x|]) {
|
|
//// a.b.c;
|
|
////
|
|
//// var numeric = 0;
|
|
//// numeric = m.n();
|
|
////
|
|
//// x.y.z
|
|
//// x.y.z.push(0);
|
|
//// return x.y.z
|
|
////}
|
|
|
|
verify.codeFix({
|
|
description: "Infer parameter types from usage",
|
|
index: 0,
|
|
newFileContent:
|
|
`/**
|
|
* @param {{ b: { c: any; }; }} a
|
|
* @param {{ n: () => number; }} m
|
|
* @param {{ y: { z: number[]; }; }} x
|
|
*/
|
|
function foo(a, m, x) {
|
|
a.b.c;
|
|
|
|
var numeric = 0;
|
|
numeric = m.n();
|
|
|
|
x.y.z
|
|
x.y.z.push(0);
|
|
return x.y.z
|
|
}`,
|
|
});
|