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

Distinguish between primitive and object types in generic type constraints? #3315

Closed
sccolbert opened this issue May 30, 2015 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@sccolbert
Copy link

With the introduction of WeakMap, the JS runtime now has restrictions on where primitive types are disallowed. Is it possible (or planned) to have language support for discriminating from primitive types and the ability to constraint generic types based on that discrimination?

From a previous SO post I made, the answer seems to be "no". But taken in light of WeakMap requirements, perhaps it can be revisited?

var a = 1;
undefined

var b = new Number(a);
undefined

var m = new WeakMap();
undefined

m.set(a, 1)
VM674:2 Uncaught TypeError: Invalid value used as weak map key
    at WeakMap.set (native)
    at <anonymous>:2:3
    at Object.InjectedScript._evaluateOn (<anonymous>:905:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)
    at Object.InjectedScript.evaluate (<anonymous>:694:21)(anonymous function) @ VM674:2InjectedScript._evaluateOn @ VM305:905InjectedScript._evaluateAndWrap @ VM305:838InjectedScript.evaluate @ VM305:694

m.set(b, 1)
WeakMap {Number {[[PrimitiveValue]]: 1} => 1}
@kitsonk
Copy link
Contributor

kitsonk commented May 31, 2015

It seems like you are asking for #1809 right?

@sccolbert
Copy link
Author

@kitsonk yes, I think #1809 would handle it.

@ghost
Copy link

ghost commented Jun 1, 2015

yes, I think #1809 would handle it.

In which case, I think this should be closed as duplicate of #1809. What do you think about that?

@sccolbert
Copy link
Author

Agreed. This is also a duplicate of #2057.

@danquirk danquirk added the Duplicate An existing issue was already created label Jun 1, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants