I'm working on a function that returns { setTimeout } when called in an environment where Jest does not exist, and { setTimeout: jest.fn() } when it does. declare namespace jest {} export type JestExists = typeof jest extends { fn: Function } ? true : false; 1/?
-
-
-
The function's return type is something like: JestExists ? Pick<Window, 'setTimeout'> : { setTimeout: jest.Mock }. Relies on *.test.* files being included in a separate tsconfig project than your source files Pretty cool IMO
2/2 - 1 more reply
New conversation -
-
-
working on a library to add side effects to "useReducer". That allows to write this code. All of it is typechecked thanks to conditional types.pic.twitter.com/dMcVyhy7Bl
- 4 more replies
New conversation -
-
-
Oh also, for a library that needs to replace everything on the Console object, this type removes the non-Function parts to leave a type with just the member functions: https://github.com/Codecademy/console-fail-test/blob/24e0841ba50176bf6e78419a6a757f063a112d80/src/types.ts#L11 …
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Matchkin (https://github.com/jviide/matchkin ) contorts conditional & inference types to implement statically checked exhaustive matching. Maybe it would've been possible to get something similar w/o those specific TS features. It has its uses, though. Sorry for the potato quality video
pic.twitter.com/OORQoiSxA0Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Oh do I have some content for you - will message when I get home
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Well the best case I’ve seen is when an API I was using sent back an integer value as both a number and a string. It completely occurred randomly
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
We had an api client that had methods for our backend services. We wanted to be able to load test new features on our production hosts without leaking the names of endpoints. Using conditional types helped us keep type safety without exposing a runtime artifact
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Matthew not Matt.
Engineer
Organizer
Broadway Fan
Slytherin

he/him