Closed
Description
Bug Report
π Search Terms
conditional
π Version & Regression Information
- This changed between versions
4.4.4
and4.5.2
β― Playground Link
Playground link with relevant code
π» Code
type KonvaEventObject<T> = {
}
export type GetMultiType<T extends string> = T extends `${infer A} ${infer B}`
? GetMultiType<A> | GetMultiType<B>
: T extends `${infer C}.${string}`
? GetMultiType<C>
: T extends keyof DocumentEventMap
? KonvaEventObject<DocumentEventMap[T]>
: T extends 'tap' | 'touchstart' | 'touchmove' | 'touchcancel' | 'touchend'
? KonvaEventObject<TouchEvent>
: KonvaEventObject<Event>
type Handler = (e: KonvaEventObject<any>) => void
const on = (type: string, handler: Handler) => {
}
const off = (type: string, handler: Handler) => {
}
export const KAD_ACTION_NS = 'kadAction'
export const withKadActionNS = (s: string) => (s.includes('.') ? s : `${s}.${KAD_ACTION_NS}`)
export const ensureWithNS = (type: string) => type.split(' ').map(withKadActionNS).join(' ')
export const onceOn = <T extends string>(target: Node, type: T, lisenter: (event: GetMultiType<T>) => void) => {
const typeWithNS = ensureWithNS(type)
const handler = (event: GetMultiType<T>) => {
lisenter(event)
// throw an error
off(typeWithNS, handler)
}
// also throw an error here
return on(typeWithNS, handler)
}
π Actual behavior
Type 'KonvaEventObject' is not assignable to type 'GetMultiType'
π Expected behavior
can assign type 'KonvaEventObject<NodeEventMap[T]>' to type 'GetMultiType'