Closed
Description
Bug Report
π Search Terms
- javascript declaration
- optional object parameters
π Version & Regression Information
- typescript 4.0
- typescript 4.1
- typescript@beta
- This changed between versions 3.x and 4.x
β― Playground Link
Playground link with relevant code (check .D.TS tab)
π» Code
jsconfig.json
{
"compilerOptions": {
"module": "es6",
"moduleResolution": "node",
"target": "es2020",
"checkJs": true,
"declaration": true,
"noEmit": false,
"emitDeclarationOnly": true
}
}
test.js
/**
* test
*
* @public
* @param {object} opts
* @param {number} opts.a
* @param {number} [opts.b]
* @param {number} [opts.c]
* @returns {number}
*/
function test({a, b, c}) {
return a + b + c;
}
npx tsc -p jsconfig.json
π Actual behavior
The definition file doesn't mark b and c as optional
test.d.ts
/**
* test
*
* @public
* @param {object} opts
* @param {number} opts.a
* @param {number} [opts.b]
* @param {number} [opts.c]
* @returns {number}
*/
declare function test({ a, b, c }: {
a: number;
b: number;
c: number;
}): number;
π Expected behavior
The definition file should mark b and c as optional (so that projects importing the definitions will be checked properly)
test.d.ts
/**
* test
*
* @public
* @param {object} opts
* @param {number} opts.a
* @param {number} [opts.b]
* @param {number} [opts.c]
* @returns {number}
*/
declare function test({ a, b, c }: {
a: number;
b?: number;
c?: number;
}): number;