Created
October 12, 2021 22:06
-
-
Save itsjohncs/963fb7b83e497dc7e4f1c2e4bc129c77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Point = [number, number] & {__brand?: any}; | |
type GridPoint = Omit<Point, "__brand"> & {__brand?: "GridPoint"}; | |
type PixelPoint = Omit<Point, "__brand"> & {__brand?: "PixelPoint"}; | |
const point: Point = [1, 2]; | |
const gridPoint: GridPoint = [1, 2]; | |
const pixelPoint: PixelPoint = [1, 2]; | |
// Points receive all | |
const _0: Point = point; | |
const _1: Point = gridPoint; | |
const _2: Point = pixelPoint; | |
// Grid point rejects PixelPoint | |
const _3: GridPoint = point; | |
const _4: GridPoint = gridPoint; | |
// @ts-expect-error | |
const _5: GridPoint = pixelPoint; | |
// Grid point rejects PixelPoint | |
const _6: PixelPoint = point; | |
// @ts-expect-error | |
const _7: PixelPoint = gridPoint; | |
const _8: PixelPoint = pixelPoint; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment