In @typedef tag, handle property with no type (#19013)

This commit is contained in:
Andy 2017-10-09 09:58:02 -07:00 committed by GitHub
parent e821c2b6e9
commit 8a55baf9a3
8 changed files with 41 additions and 5 deletions

View file

@ -2146,7 +2146,7 @@ namespace ts {
// falls through
case SyntaxKind.JSDocPropertyTag:
const propTag = node as JSDocPropertyLikeTag;
const flags = propTag.isBracketed || propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ?
const flags = propTag.isBracketed || propTag.typeExpression && propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ?
SymbolFlags.Property | SymbolFlags.Optional :
SymbolFlags.Property;
return declareSymbolAndAddToSymbolTable(propTag, flags, SymbolFlags.PropertyExcludes);

View file

@ -6699,7 +6699,7 @@ namespace ts {
if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) {
jsdocTypeLiteral.isArrayType = true;
}
typedefTag.typeExpression = childTypeTag && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ?
typedefTag.typeExpression = childTypeTag && childTypeTag.typeExpression && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ?
childTypeTag.typeExpression :
finishNode(jsdocTypeLiteral);
}

View file

@ -2194,7 +2194,7 @@ namespace ts {
export interface JSDocPropertyLikeTag extends JSDocTag, Declaration {
parent: JSDoc;
name: EntityName;
typeExpression: JSDocTypeExpression;
typeExpression?: JSDocTypeExpression;
/** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */
isNameFirst: boolean;
isBracketed: boolean;

View file

@ -1473,7 +1473,7 @@ declare namespace ts {
interface JSDocPropertyLikeTag extends JSDocTag, Declaration {
parent: JSDoc;
name: EntityName;
typeExpression: JSDocTypeExpression;
typeExpression?: JSDocTypeExpression;
/** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */
isNameFirst: boolean;
isBracketed: boolean;

View file

@ -1473,7 +1473,7 @@ declare namespace ts {
interface JSDocPropertyLikeTag extends JSDocTag, Declaration {
parent: JSDoc;
name: EntityName;
typeExpression: JSDocTypeExpression;
typeExpression?: JSDocTypeExpression;
/** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */
isNameFirst: boolean;
isBracketed: boolean;

View file

@ -0,0 +1,11 @@
=== /a.js ===
/**
* @typedef Foo
* @property foo
*/
/** @type {Foo} */
const x = { foo: 0 };
>x : Symbol(x, Decl(a.js, 6, 5))
>foo : Symbol(foo, Decl(a.js, 6, 11))

View file

@ -0,0 +1,13 @@
=== /a.js ===
/**
* @typedef Foo
* @property foo
*/
/** @type {Foo} */
const x = { foo: 0 };
>x : { foo: any; }
>{ foo: 0 } : { foo: number; }
>foo : number
>0 : 0

View file

@ -0,0 +1,12 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: /a.js
/**
* @typedef Foo
* @property foo
*/
/** @type {Foo} */
const x = { foo: 0 };