Skip to content

Commit

Permalink
Update TypeScript tests for TypeScript 4.0 (facebookexperimental#1704)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookexperimental#1704

It appears that TypeScript can produce inconsistent ordering for union types across versions while `$ExpectType` requires a consistent ordering.  (microsoft/TypeScript#17944) This can cause our TypeScript tests to break when run across multiple TypeScript versions.

Update the tests to be more robust to work across versions.

Differential Revision: D35266493

fbshipit-source-id: a7430abeabb61bfac677d0a04a015e4504905a92
  • Loading branch information
drarmstr authored and facebook-github-bot committed Apr 5, 2022
1 parent a8f2403 commit 0591fa8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## UPCOMING
**_Add new changes here as they land_**

## 0.7 (2022-03-25)
## 0.7 (2022-03-31)

### New Features
- The `default` value is now optional for `atom()` and `atomFamily()`. If not provided the atom will initialize to a pending state. (#1639)
Expand Down
21 changes: 17 additions & 4 deletions typescript/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,27 @@ useRecoilCallback(({ snapshot, set, reset, refresh, gotoSnapshot, transact_UNSTA
snapshot; // $ExpectType Snapshot
snapshot.getID(); // $ExpectType SnapshotID
await snapshot.getPromise(mySelector1); // $ExpectType number
const loadable = snapshot.getLoadable(mySelector1); // $ExpectType Loadable<number>
const loadable: Loadable<number> = snapshot.getLoadable(mySelector1);

gotoSnapshot(snapshot);

gotoSnapshot(3); // $ExpectError
gotoSnapshot(myAtom); // $ExpectError

loadable.state; // $ExpectType "hasValue" | "loading" | "hasError"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const state: 'hasValue' | 'hasError' | 'loading' = loadable.state;
loadable.contents; // $ExpectType any
switch (loadable.state) {
case 'hasValue':
loadable.contents; // $ExpectType number
break;
case 'hasError':
loadable.contents; // $ExpectType any
break;
case 'loading':
loadable.contents; // $ExpectType Promise<number>
break;
}

set(myAtom, 5);
set(myAtom, 'hello'); // $ExpectError
Expand Down Expand Up @@ -340,8 +352,9 @@ const transact: (p: number) => void = useRecoilTransaction_UNSTABLE(({get, set,
previousSnapshot.getPromise(mySelector2); // $ExpectType Promise<string>

for (const node of Array.from(snapshot.getNodes_UNSTABLE({isModified: true}))) {
const loadable = snapshot.getLoadable(node); // $ExpectType Loadable<unknown>
loadable.state; // $ExpectType "hasValue" | "loading" | "hasError"
const loadable = snapshot.getLoadable(node); // $ExpectType Loadable<unknown>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const state: 'hasValue' | 'hasError' | 'loading' = loadable.state;
}
},
);
Expand Down

0 comments on commit 0591fa8

Please sign in to comment.