Closed as not planned
Description
Bug Report
π Search Terms
NonNullable, conditional type, excessively deep
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
type StringKeys<O> = Extract<keyof O, string>;
type Values<O> = O[keyof O];
type If<Condition, Then, Else> = Condition extends true ? Then : Else;
type IsObject<T> = T extends Record<string, any> ? true : false;
type IsArray<T> = T extends Array<any> ? true : false;
interface XataRecord {
id: string;
}
type MAX_RECURSION = 5;
type NestedColumns<O, RecursivePath extends any[]> =
// this check is important too
RecursivePath["length"] extends MAX_RECURSION
? never
: Values<
{
[K in DataProps<O>]: If<
IsArray<O[K]>,
K,
// this NonNullable is important
NonNullable<O[K]> extends XataRecord
? // NestedColumns (recursive) here seems to be important
NestedColumns<
// this NonNullable is important
NonNullable<O[K]>,
// both of those are important
[...RecursivePath, O[K]]
> extends string
? `${NestedColumns<
NonNullable<O[K]>,
// both of those are important
[...RecursivePath, O[K]]
>}`
: never
: never
>;
}
>;
type DataProps<O> = Exclude<keyof O & string, keyof XataRecord>;
// it errors with this variant
// type DataProps<O> = keyof O & string;
π Actual behavior
It doesn't error on the template literal type.
π Expected behavior
It should error on the template literal type.
I believe that it should error because:
- it was an error in 4.2
- a bigger repro of this started to error in nightly versions since the
NonNullable
change (from a conditional type toT & {}
). The slimmed down version that I've created doesn't error in the nightly build though. Original repro by @SferaDev can be found here: 4.7 with no error, 4.8 nightly with the error - If we inline the
If<IsArray<O[K]>, ..., ...>
alias then it starts to error in all of the versions of the slimmed down repro: TS playground. To the best of my knowledge the aliased version and inlined version should not differ in their observable behaviors.
I understand that the repro is not small - I've tried to reduce it further but I couldn't. The problem at hand seems to be quite complex and involves a very specific ingredients from what I can tell.