diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5ab7c808f0..6260779767 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9204,12 +9204,13 @@ namespace ts { } function resolveImportSymbolType(node: ImportTypeNode, links: NodeLinks, symbol: Symbol, meaning: SymbolFlags) { - links.resolvedSymbol = symbol; + const resolvedSymbol = resolveSymbol(symbol); + links.resolvedSymbol = resolvedSymbol; if (meaning === SymbolFlags.Value) { - return links.resolvedType = getTypeOfSymbol(symbol); + return links.resolvedType = getTypeOfSymbol(symbol); // intentionally doesn't use resolved symbol so type is cached as expected on the alias } else { - return links.resolvedType = getTypeReferenceType(node, symbol); + return links.resolvedType = getTypeReferenceType(node, resolvedSymbol); // getTypeReferenceType doesn't handle aliases - it must get the resolved symbol } } diff --git a/tests/baselines/reference/declarationsForIndirectTypeAliasReference.js b/tests/baselines/reference/declarationsForIndirectTypeAliasReference.js new file mode 100644 index 0000000000..9e2f9ee403 --- /dev/null +++ b/tests/baselines/reference/declarationsForIndirectTypeAliasReference.js @@ -0,0 +1,66 @@ +//// [tests/cases/compiler/declarationsForIndirectTypeAliasReference.ts] //// + +//// [b.ts] +export { + Hash, + StringHash, StringHash2 +}; + +interface Hash { + [key: string]: T; +} + +type StringHash = Hash; + +interface StringHash2 extends Hash {} +//// [a.ts] +import {StringHash, StringHash2} from "./b"; + +export { + doSome +} + +const MAP: StringHash = { + a: "a" +}; + +const MAP2: StringHash2 = { + a: "a" +}; + +function doSome(arg1: string, + arg2 = MAP, + arg3 = MAP2) { +} + +//// [b.js] +"use strict"; +exports.__esModule = true; +//// [a.js] +"use strict"; +exports.__esModule = true; +var MAP = { + a: "a" +}; +var MAP2 = { + a: "a" +}; +function doSome(arg1, arg2, arg3) { + if (arg2 === void 0) { arg2 = MAP; } + if (arg3 === void 0) { arg3 = MAP2; } +} +exports.doSome = doSome; + + +//// [b.d.ts] +export { Hash, StringHash, StringHash2 }; +interface Hash { + [key: string]: T; +} +declare type StringHash = Hash; +interface StringHash2 extends Hash { +} +//// [a.d.ts] +import { StringHash2 } from "./b"; +export { doSome }; +declare function doSome(arg1: string, arg2?: import("./b").Hash, arg3?: StringHash2): void; diff --git a/tests/baselines/reference/declarationsForIndirectTypeAliasReference.symbols b/tests/baselines/reference/declarationsForIndirectTypeAliasReference.symbols new file mode 100644 index 0000000000..92d7fb11a4 --- /dev/null +++ b/tests/baselines/reference/declarationsForIndirectTypeAliasReference.symbols @@ -0,0 +1,68 @@ +=== tests/cases/compiler/b.ts === +export { + Hash, +>Hash : Symbol(Hash, Decl(b.ts, 0, 8)) + + StringHash, StringHash2 +>StringHash : Symbol(StringHash, Decl(b.ts, 1, 9)) +>StringHash2 : Symbol(StringHash2, Decl(b.ts, 2, 15)) + +}; + +interface Hash { +>Hash : Symbol(Hash, Decl(b.ts, 3, 2)) +>T : Symbol(T, Decl(b.ts, 5, 15)) + + [key: string]: T; +>key : Symbol(key, Decl(b.ts, 6, 5)) +>T : Symbol(T, Decl(b.ts, 5, 15)) +} + +type StringHash = Hash; +>StringHash : Symbol(StringHash, Decl(b.ts, 7, 1)) +>Hash : Symbol(Hash, Decl(b.ts, 3, 2)) + +interface StringHash2 extends Hash {} +>StringHash2 : Symbol(StringHash2, Decl(b.ts, 9, 31)) +>Hash : Symbol(Hash, Decl(b.ts, 3, 2)) + +=== tests/cases/compiler/a.ts === +import {StringHash, StringHash2} from "./b"; +>StringHash : Symbol(StringHash, Decl(a.ts, 0, 8)) +>StringHash2 : Symbol(StringHash2, Decl(a.ts, 0, 19)) + +export { + doSome +>doSome : Symbol(doSome, Decl(a.ts, 2, 8)) +} + +const MAP: StringHash = { +>MAP : Symbol(MAP, Decl(a.ts, 6, 5)) +>StringHash : Symbol(StringHash, Decl(a.ts, 0, 8)) + + a: "a" +>a : Symbol(a, Decl(a.ts, 6, 25)) + +}; + +const MAP2: StringHash2 = { +>MAP2 : Symbol(MAP2, Decl(a.ts, 10, 5)) +>StringHash2 : Symbol(StringHash2, Decl(a.ts, 0, 19)) + + a: "a" +>a : Symbol(a, Decl(a.ts, 10, 27)) + +}; + +function doSome(arg1: string, +>doSome : Symbol(doSome, Decl(a.ts, 12, 2)) +>arg1 : Symbol(arg1, Decl(a.ts, 14, 16)) + + arg2 = MAP, +>arg2 : Symbol(arg2, Decl(a.ts, 14, 29)) +>MAP : Symbol(MAP, Decl(a.ts, 6, 5)) + + arg3 = MAP2) { +>arg3 : Symbol(arg3, Decl(a.ts, 15, 27)) +>MAP2 : Symbol(MAP2, Decl(a.ts, 10, 5)) +} diff --git a/tests/baselines/reference/declarationsForIndirectTypeAliasReference.types b/tests/baselines/reference/declarationsForIndirectTypeAliasReference.types new file mode 100644 index 0000000000..7d20f7af45 --- /dev/null +++ b/tests/baselines/reference/declarationsForIndirectTypeAliasReference.types @@ -0,0 +1,72 @@ +=== tests/cases/compiler/b.ts === +export { + Hash, +>Hash : any + + StringHash, StringHash2 +>StringHash : any +>StringHash2 : any + +}; + +interface Hash { +>Hash : Hash +>T : T + + [key: string]: T; +>key : string +>T : T +} + +type StringHash = Hash; +>StringHash : Hash +>Hash : Hash + +interface StringHash2 extends Hash {} +>StringHash2 : StringHash2 +>Hash : Hash + +=== tests/cases/compiler/a.ts === +import {StringHash, StringHash2} from "./b"; +>StringHash : any +>StringHash2 : any + +export { + doSome +>doSome : (arg1: string, arg2?: import("tests/cases/compiler/b").Hash, arg3?: StringHash2) => void +} + +const MAP: StringHash = { +>MAP : import("tests/cases/compiler/b").Hash +>StringHash : import("tests/cases/compiler/b").Hash +>{ a: "a"} : { a: string; } + + a: "a" +>a : string +>"a" : "a" + +}; + +const MAP2: StringHash2 = { +>MAP2 : StringHash2 +>StringHash2 : StringHash2 +>{ a: "a"} : { a: string; } + + a: "a" +>a : string +>"a" : "a" + +}; + +function doSome(arg1: string, +>doSome : (arg1: string, arg2?: import("tests/cases/compiler/b").Hash, arg3?: StringHash2) => void +>arg1 : string + + arg2 = MAP, +>arg2 : import("tests/cases/compiler/b").Hash +>MAP : import("tests/cases/compiler/b").Hash + + arg3 = MAP2) { +>arg3 : StringHash2 +>MAP2 : StringHash2 +} diff --git a/tests/cases/compiler/declarationsForIndirectTypeAliasReference.ts b/tests/cases/compiler/declarationsForIndirectTypeAliasReference.ts new file mode 100644 index 0000000000..6b5c731c36 --- /dev/null +++ b/tests/cases/compiler/declarationsForIndirectTypeAliasReference.ts @@ -0,0 +1,33 @@ +// @declaration: true +// @filename: b.ts +export { + Hash, + StringHash, StringHash2 +}; + +interface Hash { + [key: string]: T; +} + +type StringHash = Hash; + +interface StringHash2 extends Hash {} +// @filename: a.ts +import {StringHash, StringHash2} from "./b"; + +export { + doSome +} + +const MAP: StringHash = { + a: "a" +}; + +const MAP2: StringHash2 = { + a: "a" +}; + +function doSome(arg1: string, + arg2 = MAP, + arg3 = MAP2) { +} \ No newline at end of file