Skip to content

Instantly share code, notes, and snippets.

@aiya000
Last active March 6, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aiya000/dda615ac13c3016df946f2de591606eb to your computer and use it in GitHub Desktop.
Save aiya000/dda615ac13c3016df946f2de591606eb to your computer and use it in GitHub Desktop.
/**
* The type 'true' means a proof is satisfied.
* The type 'never' means a proof is not satisfied.
*/
// Basic of this idea.
type AWrongProof = { x: number } extends { x: string } ? true : never
// Compile NG
// const aWrongProof: AWrongProof = true
// Above is samea as below.
const thatIsWrong: AWrongProof extends never ? true : never = true
// Let's introduce that alias.
type Not<A extends true | never> = A extends never ? true : never
const thatIsWrong0: Not<AWrongProof> = true
// Unfortunately, this says:
// 2322: Type 'boolean' is not assignable to type 'never'.
/**
* Why?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment