Skip to content

Type parameter constrained to number is not assignable to number #2767

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
JsonFreeman opened this issue Apr 15, 2015 · 3 comments
Closed

Type parameter constrained to number is not assignable to number #2767

JsonFreeman opened this issue Apr 15, 2015 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Spec Issues related to the TypeScript language specification

Comments

@JsonFreeman
Copy link
Contributor

enum E { x }
function enumThing<T extends number>() {
    var t: T;
    var num: number = t; // Should work
    var enumMember: E = t; // Should not work
}

Right now both of these are an error. But the number one should work because T is constrained to a number. This is useful because it means T can be a number or any enum type.

The spec and implementation would both need to be updated to allow this.

@JsonFreeman JsonFreeman added Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Apr 15, 2015
@mhegazy
Copy link
Contributor

mhegazy commented May 7, 2015

Pinging @ahejlsberg for this one.

@mhegazy mhegazy added this to the TypeScript 1.6 milestone May 7, 2015
@RyanCavanaugh
Copy link
Member

Dupe #2694?

@mhegazy
Copy link
Contributor

mhegazy commented May 7, 2015

:) yes.

@mhegazy mhegazy closed this as completed May 7, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

4 participants