Skip to content

Uninitialized instance fields are not added to instances #37043

@parzhitsky

Description

@parzhitsky

TypeScript Version: 3.9.0-dev.20200225

Search Terms: uninitialized not initialized class property in operator

Code

Looks like the same code that in JavaScript actually adds a non-static property to an instance, in TypeScript, however, does not.

class Thing {
	property;
}

const thing = new Thing();

console.log("property" in thing);

Expected behavior:

logs true

image

Actual behavior:

logs false

image

Playground Link: https://www.typescriptlang.org/play/?noImplicitAny=false&ts=3.9.0-dev.20200225#code/MYGwhgzhAEAqAWBLAdgc2gbwFAEgAOATgPZ4CmBALgJ4DcWAvllsEchBdBUmtALzTJSAdzjdUACgCUdZqwhEQpAHQgiEgESES5auugpOY6ViA

Related Issues: (none)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions