Skip to content

Commit 2243022

Browse files
committed
allow legacy primitive flagging of export= containing namespace types
1 parent 520a437 commit 2243022

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/compiler/checker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22711,9 +22711,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2271122711
function isRelatedTo(originalSource: Type, originalTarget: Type, recursionFlags: RecursionFlags = RecursionFlags.Both, reportErrors = false, headMessage?: DiagnosticMessage, intersectionState = IntersectionState.None): Ternary {
2271222712
if (originalSource === originalTarget) return Ternary.True;
2271322713

22714+
let skipPrenormalFastpath: Type | undefined;
22715+
// LEGACY COMPAT: In non-esm-compatible module loaders, and `export =` target of a primitive makes the module into that primitive.
22716+
// We restore that flag-level compatability on type originating from modules with `export=` statements here (rather than it being purely structural).
22717+
if (originalSource.symbol && originalSource.symbol.exports && hasExportAssignmentSymbol(originalSource.symbol)) {
22718+
const candidate = getTypeOfSymbol(originalSource.symbol.exports.get(InternalSymbolName.ExportEquals)!)
22719+
if (candidate.flags & TypeFlags.Primitive) {
22720+
skipPrenormalFastpath = candidate
22721+
}
22722+
}
22723+
2271422724
// Before normalization: if `source` is type an object type, and `target` is primitive,
2271522725
// skip all the checks we don't need and just return `isSimpleTypeRelatedTo` result
22716-
if (originalSource.flags & TypeFlags.Object && originalTarget.flags & TypeFlags.Primitive) {
22726+
if (!skipPrenormalFastpath && originalSource.flags & TypeFlags.Object && originalTarget.flags & TypeFlags.Primitive) {
2271722727
if (
2271822728
relation === comparableRelation && !(originalTarget.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(originalTarget, originalSource, relation) ||
2271922729
isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)
@@ -22730,7 +22740,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2273022740
// turn deferred type references into regular type references, simplify indexed access and
2273122741
// conditional types, and resolve substitution types to either the substitution (on the source
2273222742
// side) or the type variable (on the target side).
22733-
const source = getNormalizedType(originalSource, /*writing*/ false);
22743+
const source = getNormalizedType(skipPrenormalFastpath || originalSource, /*writing*/ false);
2273422744
let target = getNormalizedType(originalTarget, /*writing*/ true);
2273522745

2273622746
if (source === target) return Ternary.True;

0 commit comments

Comments
 (0)