Skip to content

Commit b932ce0

Browse files
drarmstrfacebook-github-bot
authored andcommitted
Update TypeScript tests for TypeScript 4.0 (facebookexperimental#1704)
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: 5a0e602657998d988bfa1b88d57e456561d6bc2e
1 parent d922baa commit b932ce0

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## UPCOMING
44
**_Add new changes here as they land_**
55

6-
## 0.7 (2022-03-25)
6+
## 0.7 (2022-03-31)
77

88
### New Features
99
- The `default` value is now optional for `atom()` and `atomFamily()`. If not provided the atom will initialize to a pending state. (#1639)

typescript/tests.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,27 @@ useRecoilCallback(({ snapshot, set, reset, refresh, gotoSnapshot, transact_UNSTA
290290
snapshot; // $ExpectType Snapshot
291291
snapshot.getID(); // $ExpectType SnapshotID
292292
await snapshot.getPromise(mySelector1); // $ExpectType number
293-
const loadable = snapshot.getLoadable(mySelector1); // $ExpectType Loadable<number>
293+
const loadable: Loadable<number> = snapshot.getLoadable(mySelector1);
294294

295295
gotoSnapshot(snapshot);
296296

297297
gotoSnapshot(3); // $ExpectError
298298
gotoSnapshot(myAtom); // $ExpectError
299299

300-
loadable.state; // $ExpectType "hasValue" | "loading" | "hasError"
300+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
301+
const state: 'hasValue' | 'hasError' | 'loading' = loadable.state;
301302
loadable.contents; // $ExpectType any
303+
switch (loadable.state) {
304+
case 'hasValue':
305+
loadable.contents; // $ExpectType number
306+
break;
307+
case 'hasError':
308+
loadable.contents; // $ExpectType any
309+
break;
310+
case 'loading':
311+
loadable.contents; // $ExpectType Promise<number>
312+
break;
313+
}
302314

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

342354
for (const node of Array.from(snapshot.getNodes_UNSTABLE({isModified: true}))) {
343-
const loadable = snapshot.getLoadable(node); // $ExpectType Loadable<unknown>
344-
loadable.state; // $ExpectType "hasValue" | "loading" | "hasError"
355+
const loadable = snapshot.getLoadable(node); // $ExpectType Loadable<unknown>
356+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
357+
const state: 'hasValue' | 'hasError' | 'loading' = loadable.state;
345358
}
346359
},
347360
);

0 commit comments

Comments
 (0)