* jsdoc ?Type adds optionality to parameters Chrome devtools expects that parameters with type `?T` (or `T?`) add null to `T` and optionality to the parameter. Previously it only added null to the type. Currently the PR does *not* add undefined to the type of `T`, which is expected by chrome-devtools-frontend, but is inconsistent with typescript's rules. The implementation achieves this inconsistency by exploiting the fact that checking the signature adds optionality and checking the parameter adds `undefined`. * Update chrome-devtools-frontend baseline * Add optionality only for jsdoc postfix= * Skip jsdoc prefix types in isJSDocOptionalParameter Previously isJSDocOptionalParameter was incorrect for types like `?number=`, which are optional but have JSDocNullableType as their root type node.
26 lines
376 B
TypeScript
26 lines
376 B
TypeScript
// @Filename: a.js
|
|
// @noEmit: true
|
|
// @allowJs: true
|
|
// @checkJs: true
|
|
// @strict: true
|
|
/** @param {number=} a */
|
|
function f(a) {
|
|
a = 1
|
|
a = null // should not be allowed
|
|
a = undefined
|
|
}
|
|
f()
|
|
f(null) // should not be allowed
|
|
f(undefined)
|
|
f(1)
|
|
|
|
/** @param {???!?number?=} a */
|
|
function g(a) {
|
|
a = 1
|
|
a = null
|
|
a = undefined
|
|
}
|
|
g()
|
|
g(null)
|
|
g(undefined)
|
|
g(1)
|