-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Allow referencing type-only exports as namespace members in ImportTypes and TypeQueries #49056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4110,8 +4110,10 @@ namespace ts { | |
return getMergedSymbol(symbol && (symbol.flags & SymbolFlags.ExportValue) !== 0 && symbol.exportSymbol || symbol); | ||
} | ||
|
||
function symbolIsValue(symbol: Symbol): boolean { | ||
return !!(symbol.flags & SymbolFlags.Value || symbol.flags & SymbolFlags.Alias && resolveAlias(symbol).flags & SymbolFlags.Value && !getTypeOnlyAliasDeclaration(symbol)); | ||
function symbolIsValue(symbol: Symbol, includeTypeOnlyMembers?: boolean): boolean { | ||
return !!( | ||
symbol.flags & SymbolFlags.Value || | ||
symbol.flags & SymbolFlags.Alias && resolveAlias(symbol).flags & SymbolFlags.Value && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol))); | ||
} | ||
|
||
function findConstructorDeclaration(node: ClassLikeDeclaration): ConstructorDeclaration | undefined { | ||
|
@@ -12575,12 +12577,12 @@ namespace ts { | |
* @param type a type to look up property from | ||
* @param name a name of property to look up in a given type | ||
*/ | ||
function getPropertyOfType(type: Type, name: __String, skipObjectFunctionPropertyAugment?: boolean): Symbol | undefined { | ||
function getPropertyOfType(type: Type, name: __String, skipObjectFunctionPropertyAugment?: boolean, includeTypeOnlyMembers?: boolean): Symbol | undefined { | ||
type = getReducedApparentType(type); | ||
if (type.flags & TypeFlags.Object) { | ||
const resolved = resolveStructuredTypeMembers(type as ObjectType); | ||
const symbol = resolved.members.get(name); | ||
if (symbol && symbolIsValue(symbol)) { | ||
if (symbol && symbolIsValue(symbol, includeTypeOnlyMembers)) { | ||
return symbol; | ||
} | ||
if (skipObjectFunctionPropertyAugment) return undefined; | ||
|
@@ -16208,7 +16210,7 @@ namespace ts { | |
// the `exports` lookup process that only looks up namespace members which is used for most type references | ||
const mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace)); | ||
const next = node.isTypeOf | ||
? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText) | ||
? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ true) | ||
: getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning); | ||
if (!next) { | ||
error(current, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), declarationNameToString(current)); | ||
|
@@ -28995,9 +28997,9 @@ namespace ts { | |
if (isIdentifier(left) && parentSymbol) { | ||
markAliasReferenced(parentSymbol, node); | ||
} | ||
return isErrorType(apparentType) ? errorType : apparentType;; | ||
return isErrorType(apparentType) ? errorType : apparentType; | ||
} | ||
prop = getPropertyOfType(apparentType, right.escapedText); | ||
prop = getPropertyOfType(apparentType, right.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ node.kind === SyntaxKind.QualifiedName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: is there a reason why here you used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to see if you were paying attention |
||
} | ||
// In `Foo.Bar.Baz`, 'Foo' is not referenced if 'Bar' is a const enum or a module containing only const enums. | ||
// `Foo` is also not referenced in `enum FooCopy { Bar = Foo.Bar }`, because the enum member value gets inlined | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//// [tests/cases/conformance/declarationEmit/typeofImportTypeOnlyExport.ts] //// | ||
|
||
//// [button.ts] | ||
import {classMap} from './lit.js'; | ||
export const c = classMap(); | ||
|
||
//// [lit.ts] | ||
class ClassMapDirective {} | ||
|
||
export type {ClassMapDirective}; | ||
|
||
export const directive = | ||
<C>(class_: C) => | ||
() => ({ | ||
directive: class_, | ||
}); | ||
|
||
export const classMap = directive(ClassMapDirective); | ||
|
||
|
||
//// [lit.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.classMap = exports.directive = void 0; | ||
var ClassMapDirective = /** @class */ (function () { | ||
function ClassMapDirective() { | ||
} | ||
return ClassMapDirective; | ||
}()); | ||
var directive = function (class_) { | ||
return function () { return ({ | ||
directive: class_ | ||
}); }; | ||
}; | ||
exports.directive = directive; | ||
exports.classMap = (0, exports.directive)(ClassMapDirective); | ||
//// [button.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.c = void 0; | ||
var lit_js_1 = require("./lit.js"); | ||
exports.c = (0, lit_js_1.classMap)(); | ||
|
||
|
||
//// [lit.d.ts] | ||
declare class ClassMapDirective { | ||
} | ||
export type { ClassMapDirective }; | ||
export declare const directive: <C>(class_: C) => () => { | ||
directive: C; | ||
}; | ||
export declare const classMap: () => { | ||
directive: typeof ClassMapDirective; | ||
}; | ||
//// [button.d.ts] | ||
export declare const c: { | ||
directive: typeof import("./lit.js").ClassMapDirective; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what declaration emit has always done, but was an error until now. |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
=== tests/cases/conformance/declarationEmit/button.ts === | ||
import {classMap} from './lit.js'; | ||
>classMap : Symbol(classMap, Decl(button.ts, 0, 8)) | ||
|
||
export const c = classMap(); | ||
>c : Symbol(c, Decl(button.ts, 1, 12)) | ||
>classMap : Symbol(classMap, Decl(button.ts, 0, 8)) | ||
|
||
=== tests/cases/conformance/declarationEmit/lit.ts === | ||
class ClassMapDirective {} | ||
>ClassMapDirective : Symbol(ClassMapDirective, Decl(lit.ts, 0, 0)) | ||
|
||
export type {ClassMapDirective}; | ||
>ClassMapDirective : Symbol(ClassMapDirective, Decl(lit.ts, 2, 13)) | ||
|
||
export const directive = | ||
>directive : Symbol(directive, Decl(lit.ts, 4, 12)) | ||
|
||
<C>(class_: C) => | ||
>C : Symbol(C, Decl(lit.ts, 5, 3)) | ||
>class_ : Symbol(class_, Decl(lit.ts, 5, 6)) | ||
>C : Symbol(C, Decl(lit.ts, 5, 3)) | ||
|
||
() => ({ | ||
directive: class_, | ||
>directive : Symbol(directive, Decl(lit.ts, 6, 10)) | ||
>class_ : Symbol(class_, Decl(lit.ts, 5, 6)) | ||
|
||
}); | ||
|
||
export const classMap = directive(ClassMapDirective); | ||
>classMap : Symbol(classMap, Decl(lit.ts, 10, 12)) | ||
>directive : Symbol(directive, Decl(lit.ts, 4, 12)) | ||
>ClassMapDirective : Symbol(ClassMapDirective, Decl(lit.ts, 0, 0)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
=== tests/cases/conformance/declarationEmit/button.ts === | ||
import {classMap} from './lit.js'; | ||
>classMap : () => { directive: typeof import("tests/cases/conformance/declarationEmit/lit").ClassMapDirective; } | ||
|
||
export const c = classMap(); | ||
>c : { directive: typeof import("tests/cases/conformance/declarationEmit/lit").ClassMapDirective; } | ||
>classMap() : { directive: typeof import("tests/cases/conformance/declarationEmit/lit").ClassMapDirective; } | ||
>classMap : () => { directive: typeof import("tests/cases/conformance/declarationEmit/lit").ClassMapDirective; } | ||
|
||
=== tests/cases/conformance/declarationEmit/lit.ts === | ||
class ClassMapDirective {} | ||
>ClassMapDirective : ClassMapDirective | ||
|
||
export type {ClassMapDirective}; | ||
>ClassMapDirective : ClassMapDirective | ||
|
||
export const directive = | ||
>directive : <C>(class_: C) => () => { directive: C; } | ||
|
||
<C>(class_: C) => | ||
><C>(class_: C) => () => ({ directive: class_, }) : <C>(class_: C) => () => { directive: C; } | ||
>class_ : C | ||
|
||
() => ({ | ||
>() => ({ directive: class_, }) : () => { directive: C; } | ||
>({ directive: class_, }) : { directive: C; } | ||
>{ directive: class_, } : { directive: C; } | ||
|
||
directive: class_, | ||
>directive : C | ||
>class_ : C | ||
|
||
}); | ||
|
||
export const classMap = directive(ClassMapDirective); | ||
>classMap : () => { directive: typeof ClassMapDirective; } | ||
>directive(ClassMapDirective) : () => { directive: typeof ClassMapDirective; } | ||
>directive : <C>(class_: C) => () => { directive: C; } | ||
>ClassMapDirective : typeof ClassMapDirective | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @declaration: true | ||
|
||
// @Filename: button.ts | ||
import {classMap} from './lit.js'; | ||
export const c = classMap(); | ||
|
||
// @Filename: lit.ts | ||
class ClassMapDirective {} | ||
|
||
export type {ClassMapDirective}; | ||
|
||
export const directive = | ||
<C>(class_: C) => | ||
() => ({ | ||
directive: class_, | ||
}); | ||
|
||
export const classMap = directive(ClassMapDirective); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;;
:(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sent a quick fix for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t recall seeing this or touching this line. Weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it’s because you did