Skip to content

ObjectConstructor.assign #35621

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
TrejGun opened this issue Dec 11, 2019 · 3 comments · Fixed by #40909
Closed

ObjectConstructor.assign #35621

TrejGun opened this issue Dec 11, 2019 · 3 comments · Fixed by #40909
Assignees
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@TrejGun
Copy link
Contributor

TrejGun commented Dec 11, 2019

TypeScript Version: 3.7.2

Search Terms:
ObjectConstructor, Object, assign, target, null

Code

Object.assign(null, {a:1})

this works because

    assign<T, U>(target: T, source: U): T & U;

but T can't be null

Expected behavior:
type error is risen ts and reported by typescript-eslint

Actual behavior:
type error in js

TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)

Playground Link:
http://www.typescriptlang.org/play/?ssl=1&ssc=26&pln=1&pc=21#code/PIIwVgpgxgLgdAQwM5IJYHMB2AKTBXAGwIBoACAbwQC4BGAXwEog

Related Issues:
#3429

@fatcerberus
Copy link

The typing used to be correct as the default constraint for a generic type parameter was at one time {}. It is now unknown so that should probably be changed to T extends {} to exclude null/undefined.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Dec 18, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Dec 18, 2019
@TrejGun TrejGun mentioned this issue Feb 13, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label May 20, 2020
@RyanCavanaugh RyanCavanaugh removed the Rescheduled This issue was previously scheduled to an earlier milestone label Jul 15, 2020
sandersn pushed a commit that referenced this issue Oct 2, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 2, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 11, 2020
@TrejGun
Copy link
Contributor Author

TrejGun commented Apr 6, 2021

Guys, as I understand the fix is available for almost half a year already. What prevents it from being merged?

@sandersn
Copy link
Member

sandersn commented Apr 6, 2021

We need to make sure it doesn't cause a lot of breaking changes. I ran the user tests and Definitely Typed tests to see what code there might break.

sandersn added a commit that referenced this issue Feb 18, 2022
* fixes #35621

* undo changes to generated file

* undo whitespace fixup attempt

* update baselines

Co-authored-by: TrejGun <[email protected]>
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 Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants