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

Excess properties warning with contextual type of I | object #16235

Closed
ghost opened this issue Jun 2, 2017 · 6 comments
Closed

Excess properties warning with contextual type of I | object #16235

ghost opened this issue Jun 2, 2017 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Jun 2, 2017

TypeScript Version: nightly (2.4.0-dev.20170602)

Code

interface I { x: number }
declare function f(payload: I | object): void;
f({ foo: "bar" });

Expected behavior:

No error.

Actual behavior:

src/a.ts(3,5): error TS2345: Argument of type '{ foo: string; }' is not assignable to parameter of type 'object | I'.
  Object literal may only specify known properties, and 'foo' does not exist in type 'object | I'.
@sandersn
Copy link
Member

sandersn commented Jun 5, 2017

checks for isEmptyObject should also check for isPrimitiveObject

@eliprand
Copy link

eliprand commented Jun 9, 2017

since this is a bug in 2.3.x also, are there any plans to back port it?

@mhegazy
Copy link
Contributor

mhegazy commented Jun 9, 2017

no. this should be part of TS 2.4, an RC should be out early next week.

@eliprand
Copy link

eliprand commented Jun 9, 2017

ok. So, this was not considered a backward-compatibility-breaking bug? We have code that had been compiling just fine for months that broke on our build machine when it fetched 2.3.x.
Just trying to understand how much I can trust TypeScript for production at this point...

@mhegazy
Copy link
Contributor

mhegazy commented Jun 9, 2017

Not sure we are talking about the same issue then. this error has been in 2.2, and 2.3. object was not available before 2.2, so maybe you are experiencing a different issue.

@eliprand
Copy link

eliprand commented Jun 9, 2017

@mhegazy you are correct. Looks like mongodb updated its definitions to use a custom Default type instead of any and use TypeScript 2.3. The error manifested itself the same way as the jsonwebtoken issue I reported and I jumped to a conclusion. Thanks for looking into this.

@sandersn sandersn removed this from Not started in Rolling Work Tracking Jun 28, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants