Here is a simplified version of the code snippet:
export abstract class Scheduler<TPayload> {}
export interface EventKey<T> extends Symbol {}
export type SystemSpecification<TPayload> = (
args: {
/** The value provided by current scheduler tick */
payload: TPayload;
},
) => void;
export function defineSystem<TPayload>(
system: SystemSpecification<TPayload>,
scheduler: new () => Scheduler<TPayload>
) {
// ...
}
const on = <TPayload>(eventKey: EventKey<TPayload>) =>
class extends Scheduler<TPayload> {
// ...
};
const clickEvent = Symbol('clickEvent') as EventKey<{ zoo: 30 }>;
defineSystem(
({ payload }) => console.log(payload.zoo),
on(clickEvent)
);
I expected the payload
value to be inferred from the clickEvent
type : {zoo: number}
, however, I am getting an error stating: 'payload' is of type unknown
https://i.sstatic.net/gYDCa66I.png
Am I missing something? Is it possible to infer the payload from the clickEvent type?