-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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.
interface Wrapped<T> {
valueOf(): T;
}
rylphs, bjouhier, bcherny, Taytay, ghetolay and 98 more
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript