Skip to content

Instantly share code, notes, and snippets.

@HerringtonDarkholme
Created December 3, 2020 06:47
Show Gist options
  • Save HerringtonDarkholme/293fc9fcc868aab2aa8a39e46eb8b6e5 to your computer and use it in GitHub Desktop.
Save HerringtonDarkholme/293fc9fcc868aab2aa8a39e46eb8b6e5 to your computer and use it in GitHub Desktop.
Example for comutative intersection type
// https://www.typescriptlang.org/play?ts=4.1.2#code/C4TwDgpgBAsg9gEwgGwDwwHxQLxQN4BQUxUwEAzsAFxQCMATAMwEC+UAZLAaJFAII58AOwgB3ABQBKGvCRo8AQxoNGLDC27hoAIUF4RE6bEQpUAVyEBrIXFFD1m3gGFBAztsfQAIoN2c+BARIAMbICgBO0ABuEVDBNC4EMeFQCoIGcQQKAHRp7Jw5ZJRBEKER0bEIND5JsQBG6WJQCAR1uRycbUXAQA
type Model<M> = {
test: 123
} & M
type A = {new(): Model<{a: 123}>}
type B = {new(): Model<unknown>}
type C = A & B
type D = B & A
declare var c: C
var a = new c // Model<{a: 123}>
a.a && a.test
declare var d: D
var b = new d // {test: 123}
b.a && b.test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment