Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 70cdafc

Browse files
committedNov 29, 2022
Don't add excess properties to type nodes in typeToTypeNode
1 parent 5383e15 commit 70cdafc

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
 

‎src/compiler/checker.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -6581,7 +6581,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
65816581
context.truncating = true;
65826582
}
65836583
context.approximateLength += cachedResult.addedLength;
6584-
return deepCloneOrReuseNode(cachedResult) as TypeNode as T;
6584+
return deepCloneOrReuseNode(cachedResult.node) as T;
65856585
}
65866586

65876587
let depth: number | undefined;
@@ -6597,11 +6597,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
65976597
const result = transform(type);
65986598
const addedLength = context.approximateLength - startLength;
65996599
if (!context.reportedDiagnostic && !context.encounteredError) {
6600-
if (context.truncating) {
6601-
(result as any).truncating = true;
6602-
}
6603-
(result as any).addedLength = addedLength;
6604-
links?.serializedTypes?.set(key, result as TypeNode as TypeNode & {truncating?: boolean, addedLength: number});
6600+
links?.serializedTypes?.set(key, { node: result, truncating: context.truncating, addedLength });
66056601
}
66066602
context.visitedTypes.delete(typeId);
66076603
if (id) {

‎src/compiler/types.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5936,12 +5936,19 @@ export interface NodeLinks {
59365936
isExhaustive?: boolean | 0; // Is node an exhaustive switch statement (0 indicates in-process resolution)
59375937
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
59385938
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
5939-
serializedTypes?: Map<string, TypeNode & {truncating?: boolean, addedLength: number}>; // Collection of types serialized at this location
5939+
serializedTypes?: Map<string, SerializedTypeEntry>; // Collection of types serialized at this location
59405940

59415941
contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution
59425942
inferenceContext?: InferenceContext; // Inference context for contextual type
59435943
}
59445944

5945+
/** @internal */
5946+
export interface SerializedTypeEntry {
5947+
node: TypeNode;
5948+
truncating?: boolean;
5949+
addedLength: number;
5950+
}
5951+
59455952
export const enum TypeFlags {
59465953
Any = 1 << 0,
59475954
Unknown = 1 << 1,

0 commit comments

Comments
 (0)
Please sign in to comment.