Skip to content

strictPropertyInitialization with subclasses that refine the types of properties #20911

Open
@rictic

Description

@rictic

TypeScript Version: 2.7.0-dev.20171226

Code

class A {
  x: {y: string} = {y: 'y'};
}

class B extends A {
  x: {y: string, z?: number};
}

Expected behavior:
I expected this not to warn because A#x is assignable to B#x.

Actual behavior:

index.ts(6,3): error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions