Skip to content

Possible regression in 3.1: destructured parameter is not recognized if it comes from intersection type #27927

@fictitious

Description

@fictitious

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions