* First draft:in js, constructor declaration is preferred * Add tests * initializer of null|undefined gives any in JS Also move this-assignment fixes out of binder. I'm going to put it in the checker instead. * In JS, initializer null|undefined: any, []: any[] * First draft of js prefer-ctor-types overhaul * Update tests, update baselines * Improve readability of constructor-type preference * Cleanup: Remove TODO and duplication * Add noImplicitAny errors * Add comment
59 lines
1,010 B
TypeScript
59 lines
1,010 B
TypeScript
// @allowJs: true
|
|
// @checkJs: true
|
|
// @noEmit: true
|
|
// @strictNullChecks: true
|
|
// @noImplicitAny: true
|
|
// @Filename: a.js
|
|
function A () {
|
|
// should get any on this-assignments in constructor
|
|
this.unknown = null
|
|
this.unknowable = undefined
|
|
this.empty = []
|
|
}
|
|
var a = new A()
|
|
a.unknown = 1
|
|
a.unknown = true
|
|
a.unknown = {}
|
|
a.unknown = 'hi'
|
|
a.unknowable = 1
|
|
a.unknowable = true
|
|
a.unknowable = {}
|
|
a.unknowable = 'hi'
|
|
a.empty.push(1)
|
|
a.empty.push(true)
|
|
a.empty.push({})
|
|
a.empty.push('hi')
|
|
|
|
/** @type {number | undefined} */
|
|
var n;
|
|
|
|
// should get any on parameter initialisers
|
|
function f(a = null, b = n, l = []) {
|
|
// a should be any
|
|
a = undefined
|
|
a = null
|
|
a = 1
|
|
a = true
|
|
a = {}
|
|
a = 'ok'
|
|
|
|
// b should be number | undefined, not any
|
|
b = 1
|
|
b = undefined
|
|
b = 'error'
|
|
|
|
// l should be any[]
|
|
l.push(1)
|
|
l.push('ok')
|
|
}
|
|
|
|
// should get any on variable initialisers
|
|
var u = undefined;
|
|
var l = [];
|
|
u = undefined
|
|
u = 1
|
|
u = true
|
|
u = {}
|
|
u = 'ok'
|
|
|
|
l.push('ok')
|