Skip to content

JSDoc property on typedef can only extend Object type #31410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bmeck opened this issue May 15, 2019 · 0 comments
Open

JSDoc property on typedef can only extend Object type #31410

bmeck opened this issue May 15, 2019 · 0 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@bmeck
Copy link

bmeck commented May 15, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants