Skip to content

update: about class properties #140

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

Closed
wants to merge 2 commits into from
Closed

update: about class properties #140

wants to merge 2 commits into from

Conversation

tkgkn
Copy link

@tkgkn tkgkn commented Sep 3, 2019

add a notice after class properties code example

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we had a bit of a misunderstanding. The type error is actually correct since this.pointer isn't always defined. The correct type would be pointer?: number.

Disabling the option just silences potential errors about unsound types. Please adjust the type rather than supressing errors.

@tkgkn
Copy link
Author

tkgkn commented Sep 4, 2019

Aha, I will fix that. :)
Thank you for pointing out the crux of the matter !

Copy link
Collaborator

@jsjoeio jsjoeio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested a few changes around wording to make it more clear

@@ -502,6 +502,7 @@ class App extends React.Component<{
}
}
```
Notice, if your TypeScript version before 2.7, you can declare property like `pointer: number`, but in 2.7 and later, you should declare it like `pointer?: number` or `pointer!: number`, because start with Typescript version 2.7, there is a new tsconfig option of **strictPropertyInitialization**, it will checks to esure each instance property of a class gets initialized, look at the [details](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html). Search quickly with keywords: **Strict Class Initialization**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Notice, if your TypeScript version before 2.7, you can declare property like `pointer: number`, but in 2.7 and later, you should declare it like `pointer?: number` or `pointer!: number`, because start with Typescript version 2.7, there is a new tsconfig option of **strictPropertyInitialization**, it will checks to esure each instance property of a class gets initialized, look at the [details](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html). Search quickly with keywords: **Strict Class Initialization**
Notice, if your TypeScript version before 2.7, you can declare property like `pointer: number`, but in 2.7 and later, you should declare it like `pointer?: number` or `pointer!: number`, because starting with Typescript version 2.7, there is a new tsconfig option called **strictPropertyInitialization**, which will check to ensure each instance property of a class gets initialized. For more information, refer to the [release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#strict-class-initialization).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed a few typos and changed the wording to make it more clear

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c690554125 Let me know when this is ready for re-review

@swyxio
Copy link
Collaborator

swyxio commented May 31, 2020

closing as stale

@swyxio swyxio closed this May 31, 2020
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

Successfully merging this pull request may close these issues.

4 participants