ember-cli / ember-cli/eslint-plugin-ember

New rule proposal: no-tracked-declare

Open
#2,152 1 comment 0 reactions 0 assignees View on GitHub
enhancement New Rule
Dominant language
JavaScript
Stars
263
Forks
214
Avg merge
30m
Merged PRs (30d)
5

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.