microsoft / microsoft/TypeScript
Not possible to have optional object property compatible with both Closure Compiler and Intellisense
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
- VSCode Version: 1.32.3 x64
- OS Version: Ubuntu 18.04
Steps to Reproduce:
- Enable "checkJs": true in jsconfig.json.
- Create a Javascript file:
class A {
/**
* @param {{field: string|undefined}} obj
*/
constructor(obj) {
this.obj = obj;
}
}
let a = new A({});
Results in this error:

Adding error text here for duplicate detection:
Argument of type '{}' is not assignable to parameter of type '{ field: string; }'.
Property 'field' is missing in type '{}' but required in type '{ field: string; }' .ts(2345)
Does this issue occur when all extensions are disabled?: Yes
Expected behaviour:
Some way to mark object properties as optional compatible both with Closure Compiler and VsCode intellisense. Either through @typedef, through structural interfaces with @record, direct @param notation using string|undefined, or something similar.
This notation works fine today, but it is not recognized by Closure Compiler. It is debatable whether this is an issue with Intellisense or lacking support from Closure Compiler.
class A {
/**
* @param {AParam} obj
*/
constructor(obj) {
this.obj = obj;
}
}
/** @typedef {{field?: string|undefined}} */
var AParam;
let a = new A({});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the jsconfig.json reproduction using checkJs and the JSDoc @param and @typedef forms shown in the report. Compare how TypeScript handles the optional-property notation with the stated Closure Compiler compatibility requirement. Done means a supported notation allows new A({}) without the reported missing-property error while remaining compatible with Closure Compiler.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100