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
@@ -83,6 +82,10 @@ Alternatively you can configure individual rules separately (see below).
83
82
| no-partial-array-reduce | ✅ | ✅ ||
84
83
| no-hidden-type-assertions || ✅ ||
85
84
85
+
### Deprecated rules
86
+
87
+
* no-unsafe-optional-property-assignment
88
+
86
89
### total-functions/require-strict-mode
87
90
88
91
The world is a very strange place when [strict mode](https://www.typescriptlang.org/tsconfig#strict) is disabled. This rule enforces strict mode and [noUncheckedIndexedAccess](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#no-unchecked-indexed-access) mode (which is sadly not included under the strict umbrella).
@@ -143,31 +146,6 @@ The solution is to append `as const` to the RHS:
143
146
144
147
For examples of assignment that this rule considers valid and invalid, see [no-unsafe-mutable-readonly-assignment.test.ts](https://github.com/danielnixon/eslint-plugin-total-functions/blob/master/src/rules/no-unsafe-mutable-readonly-assignment.test.ts).
Optional properties (those with a `?` after their name) interact badly with TypeScript's structural type system in a way that can lead to unsoundness. Example:
149
-
150
-
```ts
151
-
typeFoo= { readonly foo:string };
152
-
typeBar=Foo& { readonly bar?: () =>unknown };
153
-
154
-
const thing = { foo: "foo", bar: "bar" };
155
-
const foo:Foo=thing;
156
-
const bar:Bar=foo;
157
-
158
-
if (bar.bar!==undefined) {
159
-
bar.bar(); // explodes at runtime
160
-
}
161
-
```
162
-
163
-
I find this scenario particularly vexing because it doesn't require type assertions, or plain JS with incorrect \*.d.ts typings, or anything 'loose' like that. You can pull it off with otherwise nicely typed, functional TypeScript (strict mode enabled, no interfaces, no classes, everything readonly, everything const, no type assertions, no plain JS, etc).
164
-
165
-
This rule bans assignment from one type to another, if:
166
-
1. the destination type has an optional property, and
167
-
2. the source type has no matching property (either optional or otherwise).
168
-
169
-
This rule is excluded from the `recommended` config until [#83](https://github.com/danielnixon/eslint-plugin-total-functions/issues/83) lands.
170
-
171
149
### total-functions/no-enums
172
150
173
151
Enums have a number of issues, including unsoundness issues (which are especially relevant here). This rule bans the declaration of enums entirely. Use an alternative such as a union of strings instead.
0 commit comments