You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have seen some typescript ember code that incorrectly uses the declare keyword with @tracked properties like so:
@tracked declare name: string;
get formattedName() {
return this.name.toUpperCase()
}
Typescript will happily compile this code even though it is incorrectly typed and will result in runtime errors since name is initialized to undefined. There is really no good use-case for using @tracked declare but it can be incorrectly used to silence the typescript compiler in situations where the @tracked property is not initialized with a value (I'm sure there are other ways this could be abused or cause problems beyond this simple example).
Since declare is regularly and correctly used with Ember's @service decorator it can be unclear to Ember developers who are new to typescript or just unfamiliar with the declare keyword that this particular use of declare is harmful. For this reason, I think we should lint against the use of typescript's declare keyword with the @tracked decorator.
The text was updated successfully, but these errors were encountered:
I should add that I am planning to write a lint rule for this and add it to my company's internal eslint plugin, so I would be happy to contribute that work in a PR here if there is agreement that we want to add this rule to eslint-plugin-ember
I have seen some typescript ember code that incorrectly uses the
declare
keyword with@tracked
properties like so:Typescript will happily compile this code even though it is incorrectly typed and will result in runtime errors since
name
is initialized toundefined
. There is really no good use-case for using@tracked declare
but it can be incorrectly used to silence the typescript compiler in situations where the@tracked
property is not initialized with a value (I'm sure there are other ways this could be abused or cause problems beyond this simple example).Since
declare
is regularly and correctly used with Ember's@service
decorator it can be unclear to Ember developers who are new to typescript or just unfamiliar with thedeclare
keyword that this particular use ofdeclare
is harmful. For this reason, I think we should lint against the use of typescript'sdeclare
keyword with the@tracked
decorator.The text was updated successfully, but these errors were encountered: