Skip to content

Add .getTrueType() and .getFalseType() to ConditionalType #2851

@mrazauskas

Description

@mrazauskas

As a follow-up to #2831, please consider adding .getTrueType() and .getFalseType() to ConditionalType interface:

/** Conditional types — T extends U ? X : Y (TypeFlags.Conditional) */
export interface ConditionalType<Async extends boolean> extends Type<Async> {
/** Get the check type T in `T extends U ? X : Y` */
getCheckType(): MaybeAsync<Async, Type<Async>>;
/** Get the extends type U in `T extends U ? X : Y` */
getExtendsType(): MaybeAsync<Async, Type<Async>>;
}

The above interface does not provide getters for X and Y types. I can’t be sure if I am missing something, of course.

The ConditionalType interface in Strada includes resolvedTrueType?: Type and resolvedFalseType?: Type. The properties are created lazily and therefore are not very useful.

As a workaround, it is to utilize one or another .getType*() method by passing ConditionalType#root.node.trueType and ConditionalType#root.node.falseType (here, or here).

That does not work well with more complex types, because the resulting types are not instantiated.

I was playing with the internals of Strada. It seemed like the best solution would be to be able to use getTrueTypeFromConditionalType() and getFalseTypeFromConditionalType(). These method return instantiated types, but it might be that there is something more complex than I could grasp.

I only wanted to draw your attention to the missing .getTrueType() and .getFalseType() getters. And a possible solution.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions