Created
March 31, 2020 18:06
-
-
Save matiasleidemer/52ca8e2631bee0176d0cbc46b321fefb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// TypeScript-specific way to ensure that other objects with the same shape | |
// can’t be interpreted as this type | |
declare const NsType: unique symbol | |
declare const LbfsType: unique symbol | |
// Ns effectively just wraps a value of type number. | |
class Ns { | |
readonly value: number; | |
[NsType]: void | |
constructor(value: number) { | |
this.value = value | |
} | |
} | |
// Similarly, Lbfs type wraps a number and a unique symbol. | |
class Lbfs { | |
readonly value: number; | |
[LbfsType]: void | |
constructor(value: number) { | |
this.value = value | |
} | |
} | |
function lbfsToNs(lbfs: Lbfs): Ns { | |
return new Ns(lbfs.value * 4.448222) | |
} | |
function trajectoryCorrection(momentum: Ns) { | |
if (momentum.value < new Ns(2).value) { | |
// disintegrate() | |
} | |
} | |
function provideMomentum() { | |
trajectoryCorrection(lbfsToNs(new Lbfs(1.5))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment