Skip to content

Class implementation ignores optionality of method parameter in interface #27523

Closed
@maximgavrilov

Description

@maximgavrilov

TypeScript Version: 3.2.0-dev.201xxxxx

Search Terms: interface, optional parameter

Code

interface IRunner {
    run(s?: string): void;
}

class Runner implements IRunner {
    run(s: string): void {
        console.log(s.length);
    }
}

const runner: IRunner = new Runner();
runner.run(undefined);

Expected behavior:

Compilation error once strictNullChecks like TS2416: Type '(s: string) => void' is not assignable to type '(s?: string | undefined) => void'.

Actual behavior:

No compilation errors.

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions