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

Uninitialized instance fields are not added to instances #37043

Closed
parzhitsky opened this issue Feb 26, 2020 · 3 comments
Closed

Uninitialized instance fields are not added to instances #37043

parzhitsky opened this issue Feb 26, 2020 · 3 comments

Comments

@parzhitsky
Copy link

parzhitsky commented Feb 26, 2020

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)

@parzhitsky
Copy link
Author

Closed by accident :/

@IllusionMH
Copy link
Contributor

same code that in JavaScript actually adds a non-static property to an instance

Class properties in TS and JS (with class fields proposal) differs (at least at this moment #34787)

If you want to have JS behavior you should set useDefineForClassFields to true.

@parzhitsky
Copy link
Author

Seems like duplicate of #34787. Thanks @IllusionMH!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants