microsoft / microsoft/TypeScript

JSDoc property on typedef can only extend `Object` type

Open
#31,410 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JSDoc
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms: typedef jsdoc widen extend property

Code

/**
 * @typedef {Array} A
 * @property {string} a
 */
/**
 * @type {A}
 */
var a;
a.a; // Property 'a' does not exist on type 'any[]'.
/**
 * @typedef {any[]} B
 * @property {string} b
 */
/**
 * @type {B}
 */
var b;
b.b; // Property 'b' does not exist on type 'any[]'.
/**
 * @typedef {{}} C
 * @property {string} c
 */
/**
 * @type {C}
 */
var c;
c.c; // Property 'c' does not exist on type '{}'.
/**
 * @typedef {Object} O
 * @property {string} o
 */
/**
 * @type {O}
 */
var o;
o.o; // string

Expected behavior:

Other types to behave similarly? I thought non-alias typedefs would act like

type __X = {}; // from @typedef type expression
interface X extends __X {
    x: string // from @property
}

Either way of making it not work for object or allowing it to work for other types seems reasonable.

Actual behavior: Object is treated as a special type that doesn't behave like other types. See comments in example for errors when using other types.

Playground Link: it is JSDoc, can't.

Related Issues: n/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 by reproducing the JSDoc examples for typedefs based on Array, any[], {}, and Object, checking how each @property is applied. Compare the observed diagnostics with the expected behavior described in the issue, and consider the work complete when the chosen behavior is covered by regression tests for all four cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.