π Search Terms
resolvedReducedType getReducedType
β
Viability Checklist
β Suggestion
Please consider adding an API to get reduced type. Similar to getApparentType() or getContextualType(), it could be a getReducedType() method on the checker instance.
π Motivating Example
The following is a simplified reproduction of the problem:
declare const TaggedError: <Tag extends string>(
tag: Tag,
) => new <A extends Record<string, any> = {}>(
args: { readonly [P in keyof A]: A[P] },
) => { readonly _tag: Tag } & Readonly<A>;
class RateLimitError extends TaggedError("RateLimitError")<{
readonly retryAfter: number;
}> {}
class QuotaExceededError extends TaggedError("QuotaExceededError")<{
readonly limit: number;
}> {}
type Result1 = RateLimitError | (RateLimitError & QuotaExceededError);
type Result2 = RateLimitError | never;
Hovering (or using typeToString()) on Result1 and Result2 both give RateLimitError. Passing the same nodes to getTypeAtLocation() infers Result1 as a union and Result2 as plain RateLimitError.
The difference is caused by the NoTypeReduction type format flag. Enabling it in typeToString() would also return a union for Result1.
getTypeAtLocation() does not have options or flags, but similar functionality is implemented using getApparentType() or getContextualType() methods.
π» Use Cases
- What do you want to use this for?
- What shortcomings exist with current approaches?
- What workarounds are you using in the meantime?
I want to be able to get reduced type programmatically. The underlying algorithm is rather complex and seems to be hard to implement on the user side. I canβt figure out any workarounds, but it also might be that I missed something.
π Search Terms
resolvedReducedType getReducedType
β Viability Checklist
β Suggestion
Please consider adding an API to get reduced type. Similar to
getApparentType()orgetContextualType(), it could be agetReducedType()method on the checker instance.π Motivating Example
The following is a simplified reproduction of the problem:
Hovering (or using
typeToString()) onResult1andResult2both giveRateLimitError. Passing the same nodes togetTypeAtLocation()infersResult1as a union andResult2as plainRateLimitError.The difference is caused by the
NoTypeReductiontype format flag. Enabling it intypeToString()would also return a union forResult1.getTypeAtLocation()does not have options or flags, but similar functionality is implemented usinggetApparentType()orgetContextualType()methods.π» Use Cases
I want to be able to get reduced type programmatically. The underlying algorithm is rather complex and seems to be hard to implement on the user side. I canβt figure out any workarounds, but it also might be that I missed something.