Skip to content

Commit 432485f

Browse files
committed
Don't add excess properties to type nodes in typeToTypeNode
1 parent aa10969 commit 432485f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5759,7 +5759,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
57595759
context.truncating = true;
57605760
}
57615761
context.approximateLength += cachedResult.addedLength;
5762-
return deepCloneOrReuseNode(cachedResult) as TypeNode as T;
5762+
return deepCloneOrReuseNode(cachedResult.node) as T;
57635763
}
57645764

57655765
let depth: number | undefined;
@@ -5775,11 +5775,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
57755775
const result = transform(type);
57765776
const addedLength = context.approximateLength - startLength;
57775777
if (!context.reportedDiagnostic && !context.encounteredError) {
5778-
if (context.truncating) {
5779-
(result as any).truncating = true;
5780-
}
5781-
(result as any).addedLength = addedLength;
5782-
links?.serializedTypes?.set(key, result as TypeNode as TypeNode & {truncating?: boolean, addedLength: number});
5778+
links?.serializedTypes?.set(key, { node: result, truncating: context.truncating, addedLength });
57835779
}
57845780
context.visitedTypes.delete(typeId);
57855781
if (id) {

src/compiler/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5919,12 +5919,19 @@ export interface NodeLinks {
59195919
isExhaustive?: boolean | 0; // Is node an exhaustive switch statement (0 indicates in-process resolution)
59205920
skipDirectInference?: true; // Flag set by the API `getContextualType` call on a node when `Completions` is passed to force the checker to skip making inferences to a node's type
59215921
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
5922-
serializedTypes?: ESMap<string, TypeNode & {truncating?: boolean, addedLength: number}>; // Collection of types serialized at this location
5922+
serializedTypes?: ESMap<string, SerializedTypeEntry>; // Collection of types serialized at this location
59235923

59245924
contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution
59255925
inferenceContext?: InferenceContext; // Inference context for contextual type
59265926
}
59275927

5928+
/** @internal */
5929+
export interface SerializedTypeEntry {
5930+
node: TypeNode;
5931+
truncating?: boolean;
5932+
addedLength: number;
5933+
}
5934+
59285935
export const enum TypeFlags {
59295936
Any = 1 << 0,
59305937
Unknown = 1 << 1,

0 commit comments

Comments
 (0)