Type alias declarations should not return an effective annotation node (#58410)

This commit is contained in:
Wesley Wigham
2024-05-03 10:34:35 -07:00
committed by GitHub
parent 3a74ec4e99
commit e154d47851
5 changed files with 109 additions and 0 deletions

View File

@@ -6668,6 +6668,7 @@ export function getAllAccessorDeclarations(declarations: readonly Declaration[]
*/
export function getEffectiveTypeAnnotationNode(node: Node): TypeNode | undefined {
if (!isInJSFile(node) && isFunctionDeclaration(node)) return undefined;
if (isTypeAliasDeclaration(node)) return undefined; // has a .type, is not a type annotation
const type = (node as HasType).type;
if (type || !isInJSFile(node)) return type;
return isJSDocPropertyLikeTag(node) ? node.typeExpression && node.typeExpression.type : getJSDocType(node);

View File

@@ -0,0 +1,31 @@
//// [tests/cases/compiler/declarationEmitMergedAliasWithConst.ts] ////
//// [declarationEmitMergedAliasWithConst.ts]
export const Color = {
Red: "Red",
Green: "Green",
Blue: "Blue"
} as const
export type Color = typeof Color
export type Colors = Color[keyof Color]
//// [declarationEmitMergedAliasWithConst.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Color = void 0;
exports.Color = {
Red: "Red",
Green: "Green",
Blue: "Blue"
};
//// [declarationEmitMergedAliasWithConst.d.ts]
export declare const Color: {
readonly Red: "Red";
readonly Green: "Green";
readonly Blue: "Blue";
};
export type Color = typeof Color;
export type Colors = Color[keyof Color];

View File

@@ -0,0 +1,27 @@
//// [tests/cases/compiler/declarationEmitMergedAliasWithConst.ts] ////
=== declarationEmitMergedAliasWithConst.ts ===
export const Color = {
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
Red: "Red",
>Red : Symbol(Red, Decl(declarationEmitMergedAliasWithConst.ts, 0, 22))
Green: "Green",
>Green : Symbol(Green, Decl(declarationEmitMergedAliasWithConst.ts, 1, 15))
Blue: "Blue"
>Blue : Symbol(Blue, Decl(declarationEmitMergedAliasWithConst.ts, 2, 19))
} as const
>const : Symbol(const)
export type Color = typeof Color
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
export type Colors = Color[keyof Color]
>Colors : Symbol(Colors, Decl(declarationEmitMergedAliasWithConst.ts, 6, 32))
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))

View File

@@ -0,0 +1,41 @@
//// [tests/cases/compiler/declarationEmitMergedAliasWithConst.ts] ////
=== declarationEmitMergedAliasWithConst.ts ===
export const Color = {
>Color : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ Red: "Red", Green: "Green", Blue: "Blue"} as const : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ Red: "Red", Green: "Green", Blue: "Blue"} : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Red: "Red",
>Red : "Red"
> : ^^^^^
>"Red" : "Red"
> : ^^^^^
Green: "Green",
>Green : "Green"
> : ^^^^^^^
>"Green" : "Green"
> : ^^^^^^^
Blue: "Blue"
>Blue : "Blue"
> : ^^^^^^
>"Blue" : "Blue"
> : ^^^^^^
} as const
export type Color = typeof Color
>Color : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Color : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
export type Colors = Color[keyof Color]
>Colors : Colors
> : ^^^^^^

View File

@@ -0,0 +1,9 @@
// @declaration: true
export const Color = {
Red: "Red",
Green: "Green",
Blue: "Blue"
} as const
export type Color = typeof Color
export type Colors = Color[keyof Color]