IssueRaiser

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

Raise real-world problems, find people facing the same issue, and discuss solutions.7,500 issues0 comments

github (Other)

Allow wrapped values to be used in place of primitives.

icholyMar 14, 2015, 6:02 PM

``` 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.

Comment on this issue