mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Type alias declarations should not return an effective annotation node (#58410)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
> : ^^^^^^
|
||||
|
||||
@@ -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]
|
||||
Reference in New Issue
Block a user