i think im confused about how/why typescript isnt handling narrowing my union:
type CreatedGame = { state: number; code: string }
type InitialGame = { state: number; }
type MessageIn = CreatedGame | InitialGame
there's some surrounding svelte code, but when i try to pass a handler variable with type (data: CreatedGame) => void into a component that accepts a handler prop with type (data: MessageIn) => void i get the error:
Type '(data: CreatedGame) => void' is not assignable to type '(data: MessageIn) => void'.
Types of parameters 'data' and 'data' are incompatible.
Type 'MessageIn' is not assignable to type 'CreatedGame'.
Property 'code' is missing in type 'InitialGame' but required in type 'CreatedGame'.
why?
like in my head it works as "i want a component that takes a prop that can be any of the MessageIn types, so I could initialise the component either with a CreatedGame or an InitialGame"