3mcd/javelin

Can initialize function have a proper type?

Closed this issue · 2 comments

Currently following code will have an any type for the position

import { createComponentType, string, number } from '@javelin/ecs';

export const VisibleItem = createComponentType({
  name: 'VisibleItem',
  type: 1,
  schema: {
    x: number,
    y: number,
    texture: string,
  },
  initialize: (position, x = 0, y = 0) => {
    position.x = x;
    position.y = y;
  },
});

Screen Shot 2020-09-06 at 10 52 44 PM

Is it possible to properly type initialize?: I; using information from the schema: S;?

3mcd commented

Yeah, that's how it should work! What version of TypeScript are you using?

Edit -- Ahh, I found the issue. I'll get a fix up for it shortly.

3mcd commented

This is fixed in v0.19.2, which will be released shortly!