Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.