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

instanceof + extended native class #13735

Closed
GordonSmith opened this issue Jan 29, 2017 · 4 comments
Closed

instanceof + extended native class #13735

GordonSmith opened this issue Jan 29, 2017 · 4 comments

Comments

@GordonSmith
Copy link

TypeScript Version: 2.1.4

class MyC extends Error {
    constructor(msg: string) {
        super(msg);
    }
}

let myC = new MyC("Hmmm");
let test3 = myC instanceof Error;   //TRUE
let test4 = myC instanceof MyC;     //!!!FALSE!!!

Expected behavior: test4 should be TRUE

Actual behavior: test4 is FALSE

@alitaheri
Copy link

Test nightly too. It might be fixed there.

@gcnew
Copy link
Contributor

gcnew commented Jan 29, 2017

Unless you know the nits and grits of JavaScript, don't extend natives, it does't work (FAQ).

BTW: what keywords did you use to search for existing issues? This question gets asked every other day, so it seems the TS team might have to boost its discoverability, although a simple search gives plenty of good results.

@GordonSmith
Copy link
Author

That FAQ is out of date and that specific section is no longer valid since 1.6 - I did make it as far as: #1168 - still my bad for not spotting this is a duplicate and I will close.

@gcnew
Copy link
Contributor

gcnew commented Jan 29, 2017

Actually that specific section is fairly new. According to the history log (see rev 5c207fc) it is 25 days old as of today. As such it is the most recent and preferred approach.

@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
None yet
Projects
None yet
Development

No branches or pull requests

3 participants