Created
September 1, 2019 16:24
-
-
Save ELLIOTTCABLE/1c37fc8161861ffd81915f97acfd71c9 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
class Checkpoint<Semantic> { | |
type: 'Script' | 'Statement' | |
constructor(blah: any, type: 'Script'): Checkpoint<Script> | |
constructor(blah: any, type: 'Statement'): Checkpoint<Statement> | |
constructor(blah: any, type: 'Script' | 'Statement') { | |
// ... | |
this.type = type | |
} | |
producesScript(): this is Checkpoint<Script> { | |
return this.type === 'Script' | |
} | |
producesStatement(): this is Checkpoint<Script> { | |
return this.type === 'Statement' | |
} | |
f<T>(callback: (val: Semantic) => T): T { | |
// ... now do runtime type-checks, and narrow knowledge of the resultant type from `callback` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment