Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5505a09
commit 107dfc2
Showing
4 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
"@total-typescript/ts-reset": minor | ||
--- | ||
|
||
Changed the array.includes on readonly arrays to NOT be a type predicate. Before this change, this perfectly valid code would not behave correctly. | ||
|
||
```ts | ||
type Code = 0 | 1 | 2; | ||
type SpecificCode = 0 | 1; | ||
|
||
const currentCode: Code = 0; | ||
|
||
// Create an empty list of subset type | ||
const specificCodeList: ReadonlyArray<SpecificCode> = []; | ||
|
||
// This will be false, since 0 is not in [] | ||
if (specificCodeList.includes(currentCode)) { | ||
currentCode; // -> SpecificCode | ||
} else { | ||
// This branch will be entered, and ts will think z is 2, when it is actually 0 | ||
currentCode; // -> 2 | ||
} | ||
``` | ||
|
||
Removing the type predicate brings ts-reset closer towards correctness. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters