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 weak types #16333

Closed
DanielRosenwasser opened this issue Jun 7, 2017 · 2 comments
Closed

Primitives are assignable to weak types #16333

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

Comments

@DanielRosenwasser
Copy link
Member

interface Weak {
  a?: any,
  b?: any,
}
let x: Weak = 10;

Expected: Error on assigning 10 to x.
Actual: No error.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Jun 7, 2017
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.4 milestone Jun 7, 2017
@sandersn
Copy link
Member

sandersn commented Jun 7, 2017

This happens because the apparent type of number, string, etc have toString, and toString is a known property of every object type, which includes every weak type.

@sandersn
Copy link
Member

sandersn commented Jun 7, 2017

Fixed in #16343

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

3 participants