Allow wrapped values to be used in place of primitives.
``` ts class NumberWrapper { constructor(private value: number) {} valueOf(): number { return this.value; } } var x = new NumberWrapper(1); // The right-hand side of an arithmetic operation // must be of type 'any', 'number' or an enum type. console.log(2 + x); ``` It would be nice if an arithmetic operation could allow using the wrapped number because it's `valueOf()` method returns the expected primitive type. This can be generalized to: if type `T` is expected, then a value that implements the following interface can be used. ``` ts interface Wrapped<T> { valueOf(): T; } ```
Posted by icholy on Mar 14, 2015, 6:02 PM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.7,500 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
Allow wrapped values to be used in place of primitives.
``` ts class NumberWrapper { constructor(private value: number) {} valueOf(): number { return this.value; } } var x = new NumberWrapper(1); // The right-hand side of an arithmetic operation // must be of type 'any', 'number' or an enum type. console.log(2 + x); ``` It would be nice if an arithmetic operation could allow using the wrapped number because it's `valueOf()` method returns the expected primitive type. This can be generalized to: if type `T` is expected, then a value that implements the following interface can be used. ``` ts interface Wrapped<T> { valueOf(): T; } ```
Comments (0)
No comments yet. Start the discussion.