NateTheGreatt / bitECS

Flexible, minimal, data-oriented ECS library for Typescript
Mozilla Public License 2.0
944 stars 84 forks source link

Missing `readonly` in ComponentType #124

Closed dustinlacewell closed 5 days ago

dustinlacewell commented 1 year ago

In ComponentType I believe there is a missing readonly keyword when attempting to conditionally infer ListType:

  export type ComponentType<T extends ISchema> = {
    [key in keyof T]:
      T[key] extends Type
      ? ArrayByType[T[key]]
      : T[key] extends [infer RT, number]
        ? RT extends Type
          ? Array<ArrayByType[RT]>
          : unknown
        : T[key] extends ISchema
          ? ComponentType<T[key]>
          : unknown;
  };

Should read:

   export type ComponentType<T extends ISchema> = {
    [key in keyof T]:
      T[key] extends Type
      ? ArrayByType[T[key]]
      : T[key] extends readonly [infer RT, number]
        ? RT extends Type
          ? Array<ArrayByType[RT]>
          : unknown
        : T[key] extends ISchema
          ? ComponentType<T[key]>
          : unknown;
  };
NateTheGreatt commented 5 days ago

full typescript rewrite:

https://github.com/NateTheGreatt/bitECS/tree/rc-0-4-0