-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
There was a problem hiding this 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.
Aha, I will fix that. :) |
There was a problem hiding this 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** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
closing as stale |
add a notice after class properties code example