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

Primitives are assignable to Partial<T> #19519

Closed
Eyas opened this issue Oct 27, 2017 · 2 comments
Closed

Primitives are assignable to Partial<T> #19519

Eyas opened this issue Oct 27, 2017 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Eyas
Copy link
Contributor

Eyas commented Oct 27, 2017

TypeScript Version: Since at least 2.5.3 (repros in 2.7.0)

Code

const v: Partial<Window> = 5;

Expected behavior: Compilation fails saying 5 is not assignable to Partial.
Actual behavior: Compiles.

More thoughts:

While {} is assignable to Partial types, types which have no overlap in properties are not. This is helpful in catching many errors. As an extension of that, I think primitives such as number and string should not be assignable to Partials.

@mhegazy mhegazy added the Bug A bug in TypeScript label Oct 27, 2017
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Oct 27, 2017
@RyanCavanaugh
Copy link
Member

Previously #14224

@Eyas
Copy link
Contributor Author

Eyas commented Oct 27, 2017

I did see that, but I think given the work done on weak type detection in TS 2.4. Hope you agree!

@mhegazy mhegazy modified the milestones: TypeScript 2.7, TypeScript 2.8 Jan 9, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jul 2, 2018
@mhegazy mhegazy closed this as completed Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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