Skip to content

conditional generic Type assignable ErrorΒ #47127

Closed
@iahu

Description

@iahu

Bug Report

πŸ”Ž Search Terms

conditional

πŸ•— Version & Regression Information

  • This changed between versions 4.4.4 and 4.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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions