microsoft / microsoft/TypeScript

Not possible to have optional object property compatible with both Closure Compiler and Intellisense

Open
#30,522 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Proposal Suggestion
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:

  1. Enable "checkJs": true in jsconfig.json.
  2. Create a Javascript file:
class A {

  /**
   * @param {{field: string|undefined}} obj 
   */
  constructor(obj) {
    this.obj = obj;
  }
}

let a = new A({});

Results in this error:
image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.