Skip to content

Commit e154d47

Browse files
authored
Type alias declarations should not return an effective annotation node (#58410)
1 parent 3a74ec4 commit e154d47

5 files changed

+109
-0
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6668,6 +6668,7 @@ export function getAllAccessorDeclarations(declarations: readonly Declaration[]
66686668
*/
66696669
export function getEffectiveTypeAnnotationNode(node: Node): TypeNode | undefined {
66706670
if (!isInJSFile(node) && isFunctionDeclaration(node)) return undefined;
6671+
if (isTypeAliasDeclaration(node)) return undefined; // has a .type, is not a type annotation
66716672
const type = (node as HasType).type;
66726673
if (type || !isInJSFile(node)) return type;
66736674
return isJSDocPropertyLikeTag(node) ? node.typeExpression && node.typeExpression.type : getJSDocType(node);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/declarationEmitMergedAliasWithConst.ts] ////
2+
3+
//// [declarationEmitMergedAliasWithConst.ts]
4+
export const Color = {
5+
Red: "Red",
6+
Green: "Green",
7+
Blue: "Blue"
8+
} as const
9+
10+
export type Color = typeof Color
11+
export type Colors = Color[keyof Color]
12+
13+
//// [declarationEmitMergedAliasWithConst.js]
14+
"use strict";
15+
Object.defineProperty(exports, "__esModule", { value: true });
16+
exports.Color = void 0;
17+
exports.Color = {
18+
Red: "Red",
19+
Green: "Green",
20+
Blue: "Blue"
21+
};
22+
23+
24+
//// [declarationEmitMergedAliasWithConst.d.ts]
25+
export declare const Color: {
26+
readonly Red: "Red";
27+
readonly Green: "Green";
28+
readonly Blue: "Blue";
29+
};
30+
export type Color = typeof Color;
31+
export type Colors = Color[keyof Color];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/declarationEmitMergedAliasWithConst.ts] ////
2+
3+
=== declarationEmitMergedAliasWithConst.ts ===
4+
export const Color = {
5+
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
6+
7+
Red: "Red",
8+
>Red : Symbol(Red, Decl(declarationEmitMergedAliasWithConst.ts, 0, 22))
9+
10+
Green: "Green",
11+
>Green : Symbol(Green, Decl(declarationEmitMergedAliasWithConst.ts, 1, 15))
12+
13+
Blue: "Blue"
14+
>Blue : Symbol(Blue, Decl(declarationEmitMergedAliasWithConst.ts, 2, 19))
15+
16+
} as const
17+
>const : Symbol(const)
18+
19+
export type Color = typeof Color
20+
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
21+
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
22+
23+
export type Colors = Color[keyof Color]
24+
>Colors : Symbol(Colors, Decl(declarationEmitMergedAliasWithConst.ts, 6, 32))
25+
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
26+
>Color : Symbol(Color, Decl(declarationEmitMergedAliasWithConst.ts, 0, 12), Decl(declarationEmitMergedAliasWithConst.ts, 4, 10))
27+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [tests/cases/compiler/declarationEmitMergedAliasWithConst.ts] ////
2+
3+
=== declarationEmitMergedAliasWithConst.ts ===
4+
export const Color = {
5+
>Color : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
6+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
>{ Red: "Red", Green: "Green", Blue: "Blue"} as const : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
8+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
>{ Red: "Red", Green: "Green", Blue: "Blue"} : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
10+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
12+
Red: "Red",
13+
>Red : "Red"
14+
> : ^^^^^
15+
>"Red" : "Red"
16+
> : ^^^^^
17+
18+
Green: "Green",
19+
>Green : "Green"
20+
> : ^^^^^^^
21+
>"Green" : "Green"
22+
> : ^^^^^^^
23+
24+
Blue: "Blue"
25+
>Blue : "Blue"
26+
> : ^^^^^^
27+
>"Blue" : "Blue"
28+
> : ^^^^^^
29+
30+
} as const
31+
32+
export type Color = typeof Color
33+
>Color : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
34+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35+
>Color : { readonly Red: "Red"; readonly Green: "Green"; readonly Blue: "Blue"; }
36+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
38+
export type Colors = Color[keyof Color]
39+
>Colors : Colors
40+
> : ^^^^^^
41+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @declaration: true
2+
export const Color = {
3+
Red: "Red",
4+
Green: "Green",
5+
Blue: "Blue"
6+
} as const
7+
8+
export type Color = typeof Color
9+
export type Colors = Color[keyof Color]

0 commit comments

Comments
 (0)