mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 17:30:04 -05:00
Merge pull request #22308 from Microsoft/declarationEmitOfIndirectAlias
Fix incorrect error reported when using type from indirect module alias and current module is exported with "export default"
This commit is contained in:
@@ -2531,7 +2531,8 @@ namespace ts {
|
||||
// Check if symbol is any of the alias
|
||||
return forEachEntry(symbols, symbolFromSymbolTable => {
|
||||
if (symbolFromSymbolTable.flags & SymbolFlags.Alias
|
||||
&& symbolFromSymbolTable.escapedName !== "export="
|
||||
&& symbolFromSymbolTable.escapedName !== InternalSymbolName.ExportEquals
|
||||
&& symbolFromSymbolTable.escapedName !== InternalSymbolName.Default
|
||||
&& !(isUMDExportSymbol(symbolFromSymbolTable) && enclosingDeclaration && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
|
||||
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
|
||||
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
//// [tests/cases/compiler/declarationEmitAliasFromIndirectFile.ts] ////
|
||||
|
||||
//// [locale.d.ts]
|
||||
export type Locale = {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
export type CustomLocale = {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
export type key = "ar" | "bg";
|
||||
|
||||
//// [instance.d.ts]
|
||||
import { Locale, CustomLocale, key as LocaleKey } from "./locale";
|
||||
export interface FlatpickrFn {
|
||||
l10ns: {[k in LocaleKey]?: CustomLocale } & { default: Locale };
|
||||
}
|
||||
|
||||
//// [app.ts]
|
||||
import { FlatpickrFn } from "./instance";
|
||||
const fp = { l10ns: {} } as FlatpickrFn;
|
||||
export default fp.l10ns;
|
||||
|
||||
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var fp = { l10ns: {} };
|
||||
exports["default"] = fp.l10ns;
|
||||
|
||||
|
||||
//// [app.d.ts]
|
||||
declare const _default: {
|
||||
ar?: {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
bg?: {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
} & {
|
||||
default: {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,64 @@
|
||||
=== tests/cases/compiler/locale.d.ts ===
|
||||
export type Locale = {
|
||||
>Locale : Symbol(Locale, Decl(locale.d.ts, 0, 0))
|
||||
|
||||
weekdays: {
|
||||
>weekdays : Symbol(weekdays, Decl(locale.d.ts, 0, 22))
|
||||
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
>shorthand : Symbol(shorthand, Decl(locale.d.ts, 1, 15))
|
||||
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
>longhand : Symbol(longhand, Decl(locale.d.ts, 2, 76))
|
||||
|
||||
};
|
||||
};
|
||||
export type CustomLocale = {
|
||||
>CustomLocale : Symbol(CustomLocale, Decl(locale.d.ts, 5, 2))
|
||||
|
||||
weekdays: {
|
||||
>weekdays : Symbol(weekdays, Decl(locale.d.ts, 6, 28))
|
||||
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
>shorthand : Symbol(shorthand, Decl(locale.d.ts, 7, 15))
|
||||
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
>longhand : Symbol(longhand, Decl(locale.d.ts, 8, 76))
|
||||
|
||||
};
|
||||
};
|
||||
export type key = "ar" | "bg";
|
||||
>key : Symbol(key, Decl(locale.d.ts, 11, 2))
|
||||
|
||||
=== tests/cases/compiler/instance.d.ts ===
|
||||
import { Locale, CustomLocale, key as LocaleKey } from "./locale";
|
||||
>Locale : Symbol(Locale, Decl(instance.d.ts, 0, 8))
|
||||
>CustomLocale : Symbol(CustomLocale, Decl(instance.d.ts, 0, 16))
|
||||
>key : Symbol(LocaleKey, Decl(instance.d.ts, 0, 30))
|
||||
>LocaleKey : Symbol(LocaleKey, Decl(instance.d.ts, 0, 30))
|
||||
|
||||
export interface FlatpickrFn {
|
||||
>FlatpickrFn : Symbol(FlatpickrFn, Decl(instance.d.ts, 0, 66))
|
||||
|
||||
l10ns: {[k in LocaleKey]?: CustomLocale } & { default: Locale };
|
||||
>l10ns : Symbol(FlatpickrFn.l10ns, Decl(instance.d.ts, 1, 30))
|
||||
>k : Symbol(k, Decl(instance.d.ts, 2, 13))
|
||||
>LocaleKey : Symbol(LocaleKey, Decl(instance.d.ts, 0, 30))
|
||||
>CustomLocale : Symbol(CustomLocale, Decl(instance.d.ts, 0, 16))
|
||||
>default : Symbol(default, Decl(instance.d.ts, 2, 49))
|
||||
>Locale : Symbol(Locale, Decl(instance.d.ts, 0, 8))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/app.ts ===
|
||||
import { FlatpickrFn } from "./instance";
|
||||
>FlatpickrFn : Symbol(FlatpickrFn, Decl(app.ts, 0, 8))
|
||||
|
||||
const fp = { l10ns: {} } as FlatpickrFn;
|
||||
>fp : Symbol(fp, Decl(app.ts, 1, 5))
|
||||
>l10ns : Symbol(l10ns, Decl(app.ts, 1, 12))
|
||||
>FlatpickrFn : Symbol(FlatpickrFn, Decl(app.ts, 0, 8))
|
||||
|
||||
export default fp.l10ns;
|
||||
>fp : Symbol(fp, Decl(app.ts, 1, 5))
|
||||
>l10ns : Symbol(FlatpickrFn.l10ns, Decl(instance.d.ts, 1, 30))
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
=== tests/cases/compiler/locale.d.ts ===
|
||||
export type Locale = {
|
||||
>Locale : Locale
|
||||
|
||||
weekdays: {
|
||||
>weekdays : { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }
|
||||
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
>shorthand : [string, string, string, string, string, string, string]
|
||||
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
>longhand : [string, string, string, string, string, string, string]
|
||||
|
||||
};
|
||||
};
|
||||
export type CustomLocale = {
|
||||
>CustomLocale : CustomLocale
|
||||
|
||||
weekdays: {
|
||||
>weekdays : { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }
|
||||
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
>shorthand : [string, string, string, string, string, string, string]
|
||||
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
>longhand : [string, string, string, string, string, string, string]
|
||||
|
||||
};
|
||||
};
|
||||
export type key = "ar" | "bg";
|
||||
>key : key
|
||||
|
||||
=== tests/cases/compiler/instance.d.ts ===
|
||||
import { Locale, CustomLocale, key as LocaleKey } from "./locale";
|
||||
>Locale : any
|
||||
>CustomLocale : any
|
||||
>key : any
|
||||
>LocaleKey : any
|
||||
|
||||
export interface FlatpickrFn {
|
||||
>FlatpickrFn : FlatpickrFn
|
||||
|
||||
l10ns: {[k in LocaleKey]?: CustomLocale } & { default: Locale };
|
||||
>l10ns : { ar?: CustomLocale; bg?: CustomLocale; } & { default: Locale; }
|
||||
>k : k
|
||||
>LocaleKey : LocaleKey
|
||||
>CustomLocale : CustomLocale
|
||||
>default : Locale
|
||||
>Locale : Locale
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/app.ts ===
|
||||
import { FlatpickrFn } from "./instance";
|
||||
>FlatpickrFn : any
|
||||
|
||||
const fp = { l10ns: {} } as FlatpickrFn;
|
||||
>fp : FlatpickrFn
|
||||
>{ l10ns: {} } as FlatpickrFn : FlatpickrFn
|
||||
>{ l10ns: {} } : { l10ns: {}; }
|
||||
>l10ns : {}
|
||||
>{} : {}
|
||||
>FlatpickrFn : FlatpickrFn
|
||||
|
||||
export default fp.l10ns;
|
||||
>fp.l10ns : { ar?: { weekdays: { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }; }; bg?: { weekdays: { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }; }; } & { default: { weekdays: { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }; }; }
|
||||
>fp : FlatpickrFn
|
||||
>l10ns : { ar?: { weekdays: { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }; }; bg?: { weekdays: { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }; }; } & { default: { weekdays: { shorthand: [string, string, string, string, string, string, string]; longhand: [string, string, string, string, string, string, string]; }; }; }
|
||||
|
||||
@@ -56,20 +56,20 @@ declare module "foobar" {
|
||||
>"foobar" : Symbol("foobar", Decl(declarations.d.ts, 5, 1))
|
||||
|
||||
export default foo.bar;
|
||||
>foo.bar : Symbol(default, Decl(declarations.d.ts, 2, 22))
|
||||
>foo.bar : Symbol(foo.bar, Decl(declarations.d.ts, 2, 22))
|
||||
>foo : Symbol(foo, Decl(declarations.d.ts, 0, 0))
|
||||
>bar : Symbol(default, Decl(declarations.d.ts, 2, 22))
|
||||
>bar : Symbol(foo.bar, Decl(declarations.d.ts, 2, 22))
|
||||
}
|
||||
|
||||
declare module "foobarx" {
|
||||
>"foobarx" : Symbol("foobarx", Decl(declarations.d.ts, 9, 1))
|
||||
|
||||
export default foo.bar.X;
|
||||
>foo.bar.X : Symbol(default, Decl(declarations.d.ts, 2, 27), Decl(declarations.d.ts, 4, 16))
|
||||
>foo.bar.X : Symbol(foo.bar.X, Decl(declarations.d.ts, 2, 27), Decl(declarations.d.ts, 4, 16))
|
||||
>foo.bar : Symbol(foo.bar, Decl(declarations.d.ts, 2, 22))
|
||||
>foo : Symbol(foo, Decl(declarations.d.ts, 0, 0))
|
||||
>bar : Symbol(foo.bar, Decl(declarations.d.ts, 2, 22))
|
||||
>X : Symbol(default, Decl(declarations.d.ts, 2, 27), Decl(declarations.d.ts, 4, 16))
|
||||
>X : Symbol(foo.bar.X, Decl(declarations.d.ts, 2, 27), Decl(declarations.d.ts, 4, 16))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
@@ -85,9 +85,9 @@ namespace A {
|
||||
>b : Symbol(b, Decl(a.ts, 2, 37))
|
||||
}
|
||||
export default A.B;
|
||||
>A.B : Symbol(default, Decl(a.ts, 0, 13), Decl(a.ts, 1, 48))
|
||||
>A.B : Symbol(A.B, Decl(a.ts, 0, 13), Decl(a.ts, 1, 48))
|
||||
>A : Symbol(A, Decl(a.ts, 0, 0))
|
||||
>B : Symbol(default, Decl(a.ts, 0, 13), Decl(a.ts, 1, 48))
|
||||
>B : Symbol(A.B, Decl(a.ts, 0, 13), Decl(a.ts, 1, 48))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export default "foo".length;
|
||||
|
||||
@@ -59,9 +59,9 @@ declare module "foobar" {
|
||||
>"foobar" : typeof "foobar"
|
||||
|
||||
export default foo.bar;
|
||||
>foo.bar : typeof default
|
||||
>foo.bar : typeof foo.bar
|
||||
>foo : typeof foo
|
||||
>bar : typeof default
|
||||
>bar : typeof foo.bar
|
||||
}
|
||||
|
||||
declare module "foobarx" {
|
||||
@@ -89,9 +89,9 @@ namespace A {
|
||||
>0 : 0
|
||||
}
|
||||
export default A.B;
|
||||
>A.B : typeof default
|
||||
>A.B : typeof A.B
|
||||
>A : typeof A
|
||||
>B : typeof default
|
||||
>B : typeof A.B
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export default "foo".length;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
>C : Symbol(C, Decl(a.ts, 0, 0), Decl(a.ts, 4, 1))
|
||||
|
||||
static B: number;
|
||||
>B : Symbol(default, Decl(a.ts, 2, 9), Decl(a.ts, 5, 13))
|
||||
>B : Symbol(C.B, Decl(a.ts, 2, 9), Decl(a.ts, 5, 13))
|
||||
}
|
||||
namespace C {
|
||||
>C : Symbol(C, Decl(a.ts, 0, 0), Decl(a.ts, 4, 1))
|
||||
@@ -16,9 +16,9 @@ namespace C {
|
||||
}
|
||||
|
||||
export default C.B;
|
||||
>C.B : Symbol(default, Decl(a.ts, 2, 9), Decl(a.ts, 5, 13))
|
||||
>C.B : Symbol(C.B, Decl(a.ts, 2, 9), Decl(a.ts, 5, 13))
|
||||
>C : Symbol(C, Decl(a.ts, 0, 0), Decl(a.ts, 4, 1))
|
||||
>B : Symbol(default, Decl(a.ts, 2, 9), Decl(a.ts, 5, 13))
|
||||
>B : Symbol(C.B, Decl(a.ts, 2, 9), Decl(a.ts, 5, 13))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import B from "./a";
|
||||
|
||||
27
tests/cases/compiler/declarationEmitAliasFromIndirectFile.ts
Normal file
27
tests/cases/compiler/declarationEmitAliasFromIndirectFile.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// @declaration: true
|
||||
|
||||
// @filename: locale.d.ts
|
||||
export type Locale = {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
export type CustomLocale = {
|
||||
weekdays: {
|
||||
shorthand: [string, string, string, string, string, string, string];
|
||||
longhand: [string, string, string, string, string, string, string];
|
||||
};
|
||||
};
|
||||
export type key = "ar" | "bg";
|
||||
|
||||
// @filename: instance.d.ts
|
||||
import { Locale, CustomLocale, key as LocaleKey } from "./locale";
|
||||
export interface FlatpickrFn {
|
||||
l10ns: {[k in LocaleKey]?: CustomLocale } & { default: Locale };
|
||||
}
|
||||
|
||||
// @filename: app.ts
|
||||
import { FlatpickrFn } from "./instance";
|
||||
const fp = { l10ns: {} } as FlatpickrFn;
|
||||
export default fp.l10ns;
|
||||
Reference in New Issue
Block a user