Skip to content

Commit

Permalink
Don't add excess properties to type nodes in typeToTypeNode
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Nov 29, 2022
1 parent aa10969 commit 432485f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5759,7 +5759,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
context.truncating = true;
}
context.approximateLength += cachedResult.addedLength;
return deepCloneOrReuseNode(cachedResult) as TypeNode as T;
return deepCloneOrReuseNode(cachedResult.node) as T;
}

let depth: number | undefined;
Expand All @@ -5775,11 +5775,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const result = transform(type);
const addedLength = context.approximateLength - startLength;
if (!context.reportedDiagnostic && !context.encounteredError) {
if (context.truncating) {
(result as any).truncating = true;
}
(result as any).addedLength = addedLength;
links?.serializedTypes?.set(key, result as TypeNode as TypeNode & {truncating?: boolean, addedLength: number});
links?.serializedTypes?.set(key, { node: result, truncating: context.truncating, addedLength });
}
context.visitedTypes.delete(typeId);
if (id) {
Expand Down
9 changes: 8 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5919,12 +5919,19 @@ export interface NodeLinks {
isExhaustive?: boolean | 0; // Is node an exhaustive switch statement (0 indicates in-process resolution)
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
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
serializedTypes?: ESMap<string, TypeNode & {truncating?: boolean, addedLength: number}>; // Collection of types serialized at this location
serializedTypes?: ESMap<string, SerializedTypeEntry>; // Collection of types serialized at this location

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

/** @internal */
export interface SerializedTypeEntry {
node: TypeNode;
truncating?: boolean;
addedLength: number;
}

export const enum TypeFlags {
Any = 1 << 0,
Unknown = 1 << 1,
Expand Down

0 comments on commit 432485f

Please sign in to comment.