TypeScript/tests/cases/conformance/jsdoc/jsdocPostfixEqualsAddsOptionality.ts
Nathan Shively-Sanders 3b6ae8536f
JSDoc ?Type adds optionality to parameters (#22646)
* 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.
2018-03-16 13:28:24 -07:00

27 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)