-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Contextual TypesThe issue relates to contextual typesThe issue relates to contextual types
Milestone
Description
TypeScript Version: 3.2.0-dev.20181011
Search Terms: destructuring inference parameters intersection
Code
type MethodBase = { p: {}, needsPrep: 'yes' | 'no', prepArgs: {} };
type Methods = { [m in string]: MethodBase };
interface OptionsForMethodTypes<M extends MethodBase> {
'yes': { prep: (args: { p: M['p'] } & M['prepArgs']) => void };
'no': { };
}
type OptionsForMethod<M extends MethodBase> = OptionsForMethodTypes<M>[M['needsPrep']];
type Callers<MM extends Methods> = { [m in keyof MM]: (p: MM[m]['p']) => void };
type Options<MM extends Methods> = { [m in keyof MM]?: OptionsForMethod<MM[m]> };
declare function createCallers<MM extends Methods>(methods: MM, options?: Options<MM>): Callers<MM>;
const someMethods = {
a: {} as { p: string, needsPrep: 'yes', prepArgs: {foo: number} },
b: {} as { p: number, needsPrep: 'no', prepArgs: {} }
}
const c = createCallers(someMethods, {
a: { prep: ({ p, foo }) => { } },
// ERROR: Type '{ p: unknown; }' has no property 'foo' and no string index signature.
// at the same time, correct type for foo is shown in the same tooltip:
// var foo: number
});
Expected behavior:
No error. This code compiles without errors in 3.0.1
Actual behavior:
ERROR: Type '{ p: unknown; }' has no property 'foo' and no string index signature.
Playground Link: link
Related Issues:
did not find anything
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Contextual TypesThe issue relates to contextual typesThe issue relates to contextual types