Not planned
Description
π Search Terms
Infer, Generics
π Version & Regression Information
5.5.0-dev.20240229
β― Playground Link
π» Code
type EventType = number | string | symbol;
type EventOptions = {};
type EventDeclarations = Record<any, any[]>;
type Events<
T,
E,
EE extends EventDeclarations = E extends EventDeclarations ? E & { [type: EventType]: any[] } : { [type: EventType]: any[] }
> = {
[N in keyof EE]?: ((context: T, eventOptions: EventOptions, ...args: EE[N]) => void);
} & ThisType<void>;
function define<
Data extends object = {},
Methods extends Record<any, Function> = {},
Receivable extends EventDeclarations = {},
Instance = Data & Methods,
>(options: {
name: string,
types?: {
Receivable?: Receivable,
},
data?: Data,
methods?: Methods & ThisType<Instance>,
magic?: (a: Instance) => void,
interceptor?: NoInfer<Events<Instance, Receivable>>, // NoInfer is required to ensure the correct type of jjjj.a.
}) { };
define({
name: 'aaa',
types: {
Receivable: {} as {
'event': [],
'jjjj': [a: number],
'cccc': [b: string],
'cccc1': [b: string],
},
},
data: ({
bbbb: true,
gggg: () => { },
kkkk() { // If this function is commented out, magic is not needed
this.bbbb
this.kkkk
},
}),
// magic() { }, // no
magic(a) { }, // yes
interceptor: {
'jjjj'(context, options, a) {
// ^?
context.bbbb
context.gggg
context.kkkk
},
asd(context, options, a) {
},
},
});
π Actual behavior
The magic function must be added and must have parameters to be error-free.
π Expected behavior
No magic function is needed.
Perhaps an explicit command could be added to ensure waiting for certain parameter inferences to complete?
interceptor?: NoInfer<Events<FinalInfer<Instance>, Receivable>> // Add FinalInfer to ensure that the Instance is the final inference.
interceptor?: NoInfer<Events<Instance, Receivable>> & FinalInfer<Instance> // Add FinalInfer to ensure that the Instance is the final inference.
Additional information about the issue
No response
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
fatcerberus commentedon Mar 1, 2024
NoInfer<FinalInfer<T>>
seems like a contradiction: "Don't infer from here at all, but also infer from here last"?LiST-GIT commentedon Mar 1, 2024
My meaning is to wait for the inference to complete.
RyanCavanaugh commentedon Mar 1, 2024
That's not a thing
RyanCavanaugh commentedon Mar 1, 2024
We really need a minimzied repro; there's a lot going on here that doesn't seem germane to the issue being described
LiST-GIT commentedon Mar 2, 2024
I removed some of the code.
https://www.typescriptlang.org/play?ts=5.5.0-dev.20240301#code/C4TwDgpgBAogbhAdsAKuaBeKiCuBbAIwgCcoAfKAZ2GIEtEBzcqkQgewBsBuAKFElgJklADwoAfFCwBvKAG0AcgC5BSVOgC6KgBTaAxm2QQAHsBUoANFAB0tgIbEGlFXcQg5GgJRTJcNrQATbwBfXh4AMxxEPWBaQygAiHD6CBEeKAyoABE7YDsoE2AkAMooNgIAKwgYqShpYIsecW02MFjDZzr0zIDcuwB+FRy8xsyoPDsGWj1BqG07Ib7vDF9-ANHM+iLiPQg2tmJZhTYASURwkhF4NVFhu3FxKwB6J6hjs4vSWlLiCABHHC0X4BKDANgFRCUHC-UEAC2gBmIvxq-GgbHCUAqWIq1js1h4wW8slCPB4iWSiAg2mk3QyvTyOhpYzGBFZBBUNBwEA2zKgDH5DB0y0kxJ5zIA1pLxdoiRkXlAThjgLDvlBItF2ogoKqDHg8GoICC2DhgFYJlM9NrSog2MBsBBDYbabzMsrvtY2QRnS64e6peLvZkGs7CWL5ebpjK6lAGlB5SRiAdneHJpG7LLY-K2AGxlsSLt9sQVEyXQBybEVUv6QxFUxWdNdH1jeUAPX6gd5BiMpg9bI7zK7teA1gFDH7Y0HhWs-v7wZ9dkoAWr3dNUAbJd5c6DjUJvCAA
RyanCavanaugh commentedon Mar 4, 2024
Duplicate #47599
typescript-bot commentedon Mar 7, 2024
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.