Skip to content

Extending wrapper objects (e.g. Number, String, etc.) #27602

@nomadicooer

Description

@nomadicooer

I created an inheritance class,such as:

class NumberTest extends Number{
        constructor(numeric:number){
           super(numeric);
        }
}

Then I want to call the valueof method from an instance of NumberTest ,such as:

    const  numberTest=new NumberTest(4);
    numberTest.valueOf();

But unlucky,throw an error,as follow:

  TypeError: Number.prototype.valueOf requires that 'this' be a Number
        at NumberTest.valueOf (<anonymous>)

in the javascript,I created the same code,like this:

class NumberTest extends Number{
        constructor(numeric){
           super(numeric);
        }
}

It works well.
I think Number.prototype.valueOf method using the typeof judge it。so object type not number type。also this,I think this is a bug。 Shape up should extends base function。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions