Skip to content
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

Object.assign({}) seems to always return a type any #29348

Open
doberkofler opened this issue Jan 10, 2019 · 1 comment
Open

Object.assign({}) seems to always return a type any #29348

doberkofler opened this issue Jan 10, 2019 · 1 comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@doberkofler
Copy link

doberkofler commented Jan 10, 2019

TypeScript Version: 3.3.0-dev.20190110

Search Terms: Object.assign

Code

function foo(): {foo: string} {
    return Object.assign({});
}

Interestingly the code:

function bar(): {bar: string} {
    return Object.assign({}, {bar: 1});
}

does report the expected error

Expected behavior: TypeScript should report an error because the type returned by return Object.assign({}); does not mach {foo: string} but instead the type any is assumed.

Actual behavior: No error is shown

Playground Link: https://www.typescriptlang.org/play/index.html#src=function%20foo()%3A%20%7Bfoo%3A%20string%7D%20%7B%0D%0A%20%20%20%20return%20Object.assign(%7B%7D)%3B%0D%0A%7D%0D%0A

Related Issues: no

@doberkofler doberkofler changed the title Object.assert({}) Object.assert({}) seems to always return a type any Jan 10, 2019
@weswigham weswigham changed the title Object.assert({}) seems to always return a type any Object.assign({}) seems to always return a type any Jan 10, 2019
@weswigham weswigham added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jan 10, 2019
@weswigham
Copy link
Member

We should probably make it forbidden for the catch-all signature on Object.assign to take a single argument.

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: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants