-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Support typedef inheritance with JSDoc #20077
Comments
For what it's worth, I also tried the following combinations. Both result in /**
* @typedef {Object} Child
* @extends Base
* @property {String} childProp
*/ /**
* @typedef {Object} Child
* @mixes Base
* @property {String} childProp
*/ |
You can use an Intersection Type notation there: /**
* @typedef {Base & {childProp: String}} Child
*/ or /**
* @typedef {Object} ChildType
* @property {String} childProp
*
* @typedef {Base & ChildType} Child
*/ should both work. |
@ekulabuhov life saver! |
Although the // won't work, and no workaround at all
/**
* @typedef {number|ArrayjOfValue} value
*/
/**
* @typedef {Array<value>} ArrayjOfValue
*/
/**
* @type {value}
*/
var k1 = [1, [1]] // works
type value = number | ArrayOfValue;
interface ArrayOfValue extends Array<value> {}
var k1: value = [1, [1]] The While the I think Or it will make the But I don't have any idea whether it will break existing code or not. And whether |
For JSDoc code already using this, it'd be nice to have compatibility. Same for interface/implements.... |
(Pardon perhaps silly question regarding JSDoc behavior in current VSCode.) "Intersection Type notation" from ekulabuhov's comment somewhat works in current VSCode but only when used like /**
* @typedef movable
* @property {function} moveMe
*/
/**
* @typedef {movable & HTMLElement} movableElement
*/
/** @type movableElement */
var myElement = document.querySelector('#myElement');
myElement.moveMe; // OK, function
myElement.tabIndex; // OK, number
myElement.error_test; // OK, does not exist But straightforward declaration of custom type with base type and custom property /**
* @typedef {HTMLElement} movableElement
* @property {function} moveMe
*/ results in simply aliasing type movableElement = HTMLElement & { moveMe: Function };
var myElement: movableElement = document.querySelector('#myElement');
myElement.tabIndex; // OK, number
myElement.moveMe; // OK, Function
myElement.error_test; // OK, does not exist works as expected. BTW, if that Intersection Type notation is standard and stable already, it should be probably mentioned in https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript (?) |
This would be really great as intersection types "&" are not going to to be supported by jsdoc. |
See microsoft/TypeScript#20077 for more informations
Any valid @jsdoc solution yet? |
Is there a way to add a description to the child property created with /**
* @typedef {Base & {childProp: String}} Child
*/ without creating a single-serving proxy type with |
@mhegazy I believe this issue needs re-triage. Namely, removing It makes no sense for TypeScript to rely on JSDoc for type resolution, but at the same time require JSDoc to not be JSDoc and use TS declarations which can't be supported:
chriseaton created a plugin that intecepts these for JSDoc A solution for this is preprocess JSDoc comments on TS side when they're acquired and perform transformation described by comments in this issue - extract all unused annotations into a separate internal type and use that type & original as definition for target type. |
TypeScript Version: 2.7.0-dev.20171116
Code
Expected behavior: Error.
child
is missing thechildProp
property.Actual behavior: No error. The
Child
type is identical to theBase
type and only requires abaseProp
property. ThechildProp
property definition is completely ignored.Or maybe there's another way to do the equivalent of
interface Child extends Base
here?The text was updated successfully, but these errors were encountered: