-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
Notably, this does not show up in the editor. I haven't got it to reproduce outside the jquery project either:
- You can see this error with
npm test jquery
inside Definitely Typed. - Or you can observe that
tsc
before Support re-aliasing of type alias instantiations #42284 has 12 (expected) errors, whereastsc
afterward has 14 errors. - Or you can paste this code into a test file (I used jquery-slim-no-window-module-tests.ts), since it's a smaller repro:
function delegate_0(events: string, handler: JQuery.TypeEventHandler<HTMLElement, any, any, any, string>) {
delegate(events, handler);
}
declare function delegate<TType extends string>(eventType: TType, handler: JQuery.TypeEventHandler<HTMLElement, any, any, any, TType>): void;
Expected: No error on the argument events
Actual: Error on the argument events
: "Argument of type 'string' is not assignable to parameter of type "myEvent"."
It looks like TType is inferred as "myEvent"
instead of string
. I can't figure out why. TType should be constrained to string | number
, since its constraint as written is TType extends keyof TypeToTriggeredEventMap<TDelegateTarget, TData, TCurrentTarget, TTarget>
and TypeToTriggeredEventMap has a string index signature (plus a dozen properties or so).
Changing events
to "myEvent"
gets rid of the error.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.