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

Why does this compile!!?? #3489

Closed
blendsdk opened this issue Jun 12, 2015 · 2 comments
Closed

Why does this compile!!?? #3489

blendsdk opened this issue Jun 12, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@blendsdk
Copy link

Hi,

I was wondering why the code below compiles fine!
The compiler should complain for the last two lines, not?

interface ViewConfig {
    width?:number;
    height?:number;
}

interface ToolbarConfig {
    size?:number
}

class View implements ViewConfig {
    width:number;
    height:number;
    constructor(config:ViewConfig) {

    }
}

class Toolbar extends View implements ToolbarConfig {
    size:number;
    constructor(config:ToolbarConfig) {
        super(config);
    }
}


var myToolbar = new Toolbar('should not compile');
var myToolbar = new Toolbar(9999);
@carltonf
Copy link

Aren't all properties in the interface are optional? The it's ok that they are not there.
See http://www.typescriptlang.org/Handbook#interfaces-optional-properties

Quote: "The advantage of optional properties is that you can describe these possibly available properties while still also catching properties that you know are not expected to be available."

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 12, 2015
@RyanCavanaugh
Copy link
Member

It's a structural type system, so an interface with all optional properties is assignable from anything.

This is a known pain point; see #391.

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants