Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My compile time went from seconds to minutes when I made a recursive immutable type (which I reverted of course). Overall, I still love typescript.

Edit for the curious, here's the monster type that caused such pathological build times...

  type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
  export type Immutable<T> =
    T extends ImmutablePrimitive ? T :
    T extends [infer U]                                     ? readonly [Immutable<U>] :
    T extends [infer U, infer V]                            ? readonly [Immutable<U>, Immutable<V>] :
    T extends [infer U, infer V, infer X]                   ? readonly [Immutable<U>, Immutable<V>, Immutable<X>] :
    T extends [infer U, infer V, infer X, infer Y]          ? readonly [Immutable<U>, Immutable<V>, Immutable<X>, Immutable<Y>] :
    T extends [infer U, infer V, infer X, infer Y, infer Z] ? readonly [Immutable<U>, Immutable<V>, Immutable<X>, Immutable<Y>, Immutable<Z>] :
    T extends readonly [infer U]                                     ? readonly [Immutable<U>] :
    T extends readonly [infer U, infer V]                            ? readonly [Immutable<U>, Immutable<V>] :
    T extends readonly [infer U, infer V, infer X]                   ? readonly [Immutable<U>, Immutable<V>, Immutable<X>] :
    T extends readonly [infer U, infer V, infer X, infer Y]          ? readonly [Immutable<U>, Immutable<V>, Immutable<X>, Immutable<Y>] :
    T extends readonly [infer U, infer V, infer X, infer Y, infer Z] ? readonly [Immutable<U>, Immutable<V>, Immutable<X>, Immutable<Y>, Immutable<Z>] :
    T extends Array<infer U> ? ImmutableArray<U> :
    T extends ReadonlyArray<infer U> ? ImmutableArray<U> :
    T extends Map<infer K, infer V> ? ImmutableMap<K, V> :
    T extends ReadonlyMap<infer K, infer V> ? ImmutableMap<K, V> :
    T extends Set<infer M> ? ImmutableSet<M> :
    T extends ReadonlySet<infer M> ? ImmutableSet<M> :
    ImmutableObject<T>;
  type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
  type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
  type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
  type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: