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

Inconsistency between Object Literal and constructor in strictNullChecks mode #9773

Closed
DJCordhose opened this issue Jul 16, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@DJCordhose
Copy link

TypeScript Version: (2.0.0-beta)

"strictNullChecks": true

Code

class Person {
    name: string;
    constructor() {
        // why no error?
    }
}

const olli: Person = new Person();

Expected behavior:

Should issue error like in this example:

const daniel: Person = {
};

error:

error TS2322: Type '{}' is not assignable to type 'Person'.
  Property 'name' is missing in type '{}'.

Actual behavior:

shows no error

@mvestergaard
Copy link

+1 this seems wrong and leads to inconsistencies. It should require me to set the property in the constructor if undefined is not allowed.

@nippur72
Copy link

@mvestergaard it seems this is a wontfix, see #8476

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 18, 2016
@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

4 participants