Skip to content

conditional generic Type assignable Error #47127

Closed

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'

Activity

  1. RyanCavanaugh commented on Dec 13, 2021

    @RyanCavanaugh
    Member

    Bisect to #46429

  2. RyanCavanaugh commented on Dec 13, 2021

    @RyanCavanaugh
    Member

    Simplified

    type EventWrapper<T> = {
      event: T;
    }
    
    export type GetEventType<T extends string> =
      T extends `${infer A} ${string}` ?
        GetEventType<A>
        : T extends keyof DocumentEventMap ?
          EventWrapper<DocumentEventMap[T]>
        : EventWrapper<Event>
    
    function go<T extends string>(type: T, lisenter: (event: GetEventType<T>) => void) {
      const src: EventWrapper<any> = null as any;
      // OK in 4.4, error in 4.5
      // Should be OK [?]; all terminuses of GetEventType<T> are EventWrapper<any>'s
      const dst: GetEventType<T> = src;
    }
  3. added
    Needs Investigation
    on Dec 13, 2021
  4. removed
    Needs Investigation
    on Dec 13, 2021
  5. RyanCavanaugh commented on Dec 13, 2021

    @RyanCavanaugh
    Member

    FYI Anders Hejlsberg (@ahejlsberg) for visibility anyway

  6. added
    Working as Intended
    on Dec 14, 2021
  7. typescript-bot commented on Dec 17, 2021

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  8. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as Intended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions