Skip to content

compiler throws a false positive on interface conformance #7103

Closed
@bcherny

Description

@bcherny

is there a better way to express this, without explicitly listing out every member of the interface?

interface Foo {
    a: string
}

// ok
class Bar implements Foo {
    constructor (public a: string) {}
}

// Error: Class 'Baz' incorrectly implements interface 'Foo'.
//        Property 'a' is missing in type 'Baz'
class Baz implements Foo {
    constructor (a: Foo) {
        Object.assign(this, a)
    }
}

demo: http://www.typescriptlang.org/Playground#src=interface%20Foo%20%7B%0A%09a%3A%20string%0A%7D%0A%0A%2F%2F%20ok%0Aclass%20Bar%20implements%20Foo%20%7B%0A%09constructor%20(public%20a%3A%20string)%20%7B%7D%0A%7D%0A%0A%2F%2F%20Error%3A%20Class%20'Baz'%20incorrectly%20implements%20interface%20'Foo'.%0A%2F%2F%20%20%20%20%20%20%20%20Property%20'a'%20is%20missing%20in%20type%20'Baz'%0Aclass%20Baz%20implements%20Foo%20%7B%0A%09constructor%20(a%3A%20Foo)%20%7B%0A%09%09Object.assign(this%2C%20a)%0A%09%7D%0A%7D

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions