Closed namiwang closed 1 year ago
Thanks for opening the issue.
I see it's broken This only happens when just calling defineHex()
and assigning the result to a variable (not using class
), right?
const CustomHex = defineHex()
const grid = new Grid(CustomHex)
// ^ Grid<Hex>
Or do you see more scenarios where you get Grid<Hex>
and expect something else?
This has the expected type:
class CustomHex extends defineHex() {}
const grid = new Grid(CustomHex)
// ^ Grid<CustomHex>
With this code:
const CustomHex = defineHex()
const grid = new Grid(CustomHex)
// ^ Grid<Hex>
I don't see how it's possible to make grid
have the type Grid<CustomHex>
(except for what you already mentioned: as unknown as Grid<CustomHex>
).
So, unless there are other scenarios where you expect Grid<CustomHex>
but get Grid<Hex>
as a type, this seems a non-issue.
I'm indeed using a custom class like this
export default class CDHex extends Hex { ... }
const spiralTraverser = spiral( ... )
const grid = new Grid(CustomHex, spiralTraverser)
^ Grid<Hex> by default
And I just found that the correct way to infer the type is to add typings to spiral
export default class CustomHex extends Hex { ... }
const spiralTraverser = spiral<CustomHex>( ... )
const grid = new Grid<CustomHex>(CustomHex, spiralTraverser)
^ Grid<CustomHex>
So yeah, I think there's no issue here. Thanks for the details.
new Grid()
always has a type ofGrid<Hex>
, even with a custom Hex class.A workaround is
new Grid(CustomHex, spiralTraverser) as unknown as Grid<CustomHex>