Mark @typedef as a type declaration (#39468)

* Mark @typedef as a type declaration

This is only important right now for marking uses of deprecated tags due
to the way that deprecated type references are computed. But I'm
surprised it hasn't caused problems elsewhere.

Fixes #39466

* Also mark @callback and @enum

Requires making name lookup in isTypeDeclarationName smarter, but this
is only used by services, so shouldn't be too performance sensitive.
This commit is contained in:
Nathan Shively-Sanders
2020-07-07 10:37:52 -07:00
committed by GitHub
parent 6b493f2048
commit 1814e2a5c4
2 changed files with 28 additions and 2 deletions

View File

@@ -36107,16 +36107,19 @@ namespace ts {
function isTypeDeclarationName(name: Node): boolean {
return name.kind === SyntaxKind.Identifier &&
isTypeDeclaration(name.parent) &&
name.parent.name === name;
getNameOfDeclaration(name.parent) === name;
}
function isTypeDeclaration(node: Node): node is TypeParameterDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ImportClause | ImportSpecifier | ExportSpecifier {
function isTypeDeclaration(node: Node): node is TypeParameterDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag | EnumDeclaration | ImportClause | ImportSpecifier | ExportSpecifier {
switch (node.kind) {
case SyntaxKind.TypeParameter:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.JSDocTypedefTag:
case SyntaxKind.JSDocCallbackTag:
case SyntaxKind.JSDocEnumTag:
return true;
case SyntaxKind.ImportClause:
return (node as ImportClause).isTypeOnly;

View File

@@ -0,0 +1,23 @@
///<reference path="fourslash.ts" />
// @checkJs: true
// @allowJs: true
// @Filename: jsdocDeprecated_suggestion5.js
//// /** @typedef {{ email: string, nickName?: string }} U2 */
//// /** @type {U2} */
//// const u2 = { email: "" }
//// /**
//// * @callback K
//// * @param {any} ctx
//// * @return {void}
//// */
//// /** @type {K} */
//// const cc = _k => {}
//// /** @enum {number} */
//// const DOOM = { e: 1, m: 1 }
//// /** @type {DOOM} */
//// const kneeDeep = DOOM.e
verify.getSuggestionDiagnostics([])