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

Interface extending Array loses all type safety #5772

Open
massimonewsuk opened this issue Feb 5, 2018 · 3 comments
Open

Interface extending Array loses all type safety #5772

massimonewsuk opened this issue Feb 5, 2018 · 3 comments
Labels

Comments

@massimonewsuk
Copy link

interface NumberArray extends Array<number> { }

function doSomething(x: NumberArray | null) {
    if (Array.isArray(x)) {
        printString(x); // Why does this work?
        printNumber(x); // Why does this work?
        printBoolean(x); // Why does this work?
        printArray(x);
    }
}

function printString(x: string) {
}

function printNumber(x: number) {
}

function printBoolean(x: boolean) {
}

function printArray(x: Array<any>) {
}

If I use type NumberArray = Array<number>; then everything works as expected.

I tried this in the TypeScript playground and the errors show up as expected. I tried reading Flow's documentation on interfaces but I couldn't find any reason why the declaration using interface shouldn't work (versus type).

This issue might be related to #5759 where the interface keyword acts differently to the type keyword.

@massimonewsuk
Copy link
Author

Still an issue in v0.67.0

@vkurchatkin vkurchatkin added the bug label Mar 7, 2018
@massimonewsuk
Copy link
Author

Still an issue in v0.70.0

@Mocha--
Copy link

Mocha-- commented Sep 5, 2018

Guys, any update for this issue?

I got the same severe problem in my code. All properties are lost, which are supposed to be inherited from its parent interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants