reduxjs / reselect

Selector library for Redux
MIT License
19.03k stars 671 forks source link

Question: What are the rules for TS2589 (infinite type instantiation)? #727

Closed DavidHancu closed 2 months ago

DavidHancu commented 2 months ago

Hi! As the title says, I'm wondering why TypeScript doesn't catch this infinite recursion unless I actually use the type.

// No errors in this code!
type s3<a extends readonly string[]> = a extends [
    infer b extends string,
    ...infer c extends readonly string[]
]
    ? s3<c>
    : s3<a>;
//    ^^^^^ This is definitely causing infinite recursion 
 type s3<a extends readonly string[]> = a extends [
    infer b extends string,
    ...infer c extends readonly string[]
]
    ? s3<c>
    : s3<a>;

type L = s3<["hi"]>;
//       ^^^^^^^^^^ Error: Type instantiation is excessively deep and possibly infinite.

I'm just wondering what the heuristics for this are. Thanks in advance!

DavidHancu commented 2 months ago

Sorry I've opened the issue in the wrong repository.