c9ac15ae56
* 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
36 lines
946 B
TypeScript
36 lines
946 B
TypeScript
// @allowJs: true
|
|
// @checkJs: true
|
|
// @noEmit: true
|
|
// @strictNullChecks: true
|
|
// @noImplicitAny: true
|
|
// @Filename: a.js
|
|
function Installer () {
|
|
// arg: number
|
|
this.arg = 0
|
|
// unknown: string | boolean | null
|
|
this.unknown = null
|
|
// twice: string | undefined
|
|
this.twice = undefined
|
|
this.twice = 'hi'
|
|
// twices: any[] | null
|
|
this.twices = []
|
|
this.twices = null
|
|
}
|
|
Installer.prototype.first = function () {
|
|
this.arg = 'hi' // error
|
|
this.unknown = 'hi' // ok
|
|
this.newProperty = 1 // ok: number | boolean
|
|
this.twice = undefined // ok
|
|
this.twice = 'hi' // ok
|
|
}
|
|
Installer.prototype.second = function () {
|
|
this.arg = false // error
|
|
this.unknown = false // ok
|
|
this.newProperty = false // ok
|
|
this.twice = null // error
|
|
this.twice = false // error
|
|
this.twices.push(1) // error: Object is possibly null
|
|
if (this.twices != null) {
|
|
this.twices.push('hi')
|
|
}
|
|
}
|