Skip to content

Fail to get contextual type when an index signature exists #27949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Oct 17, 2018 · 0 comments
Closed

Fail to get contextual type when an index signature exists #27949

ghost opened this issue Oct 17, 2018 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Contextual Types The issue relates to contextual types Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Oct 17, 2018

TypeScript Version: 3.2.0-dev.20181017

Code

interface Options {
    m(x: number): void;
    [key: string]: unknown;
}
declare function f(options: number | Options): void;
f({
    m(x) {},
});

Expected behavior:

No error.

Actual behavior:

src/a.ts:7:7 - error TS7006: Parameter 'x' implicitly has an 'any' type.

Was introduced by #27849. For some reason it only happens when options is a union. Discovered in jquery on DefinitelyTyped.

@ghost ghost added the Bug A bug in TypeScript label Oct 17, 2018
@ghost ghost assigned sheetalkamat Oct 17, 2018
@ghost ghost added the Domain: Contextual Types The issue relates to contextual types label Oct 17, 2018
@sheetalkamat sheetalkamat added Fixed A PR has been merged for this issue Design Limitation Constraints of the existing architecture prevent this from being fixed and removed Design Limitation Constraints of the existing architecture prevent this from being fixed labels Oct 17, 2018
sheetalkamat added a commit that referenced this issue Oct 17, 2018
…om unit type(fix the incorrectly used union type to get the signature)

Fixes #27949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Contextual Types The issue relates to contextual types Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

1 participant