TypeScript/tests/cases/fourslash/codeFixInferFromUsageMemberJS.ts

41 lines
995 B
TypeScript
Raw Normal View History

/// <reference path='fourslash.ts' />
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @strictNullChecks: true
// @Filename: important.js
////class C {
//// constructor() {
2018-10-25 01:14:52 +02:00
//// /** this is fine */
//// this.p = undefined;
//// this.q = undefined
//// }
//// method() {
//// this.p.push(1)
2018-10-25 01:14:52 +02:00
//// this.q.push(1);
//// }
////}
// Note: Should be number[] | undefined, but inference currently privileges assignments
// over usage (even when the only result is undefined) and infers only undefined.
2018-10-25 01:14:52 +02:00
verify.codeFixAll({
fixId: "inferFromUsage",
fixAllDescription: "Infer all types from usage",
newFileContent:
`class C {
constructor() {
2018-10-25 01:14:52 +02:00
/**
* this is fine
* @type {undefined}
*/
this.p = undefined;
2018-10-25 01:14:52 +02:00
/** @type {undefined} */
this.q = undefined
}
method() {
this.p.push(1)
2018-10-25 01:14:52 +02:00
this.q.push(1);
}
2018-10-25 01:14:52 +02:00
}`});