Last active
December 21, 2018 15:29
-
-
Save P4/b2382153282f1f86345cb8bf3239b4f0 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
interface Inner<T> { | |
value: T; | |
} | |
interface Numeric { | |
content: Inner<number>; | |
} | |
interface Text { | |
content: Inner<string>; | |
} | |
type Expr = Text | Numeric; | |
function evaluate<T>(content: Inner<T>): T { | |
return content.value; | |
} | |
// compiles | |
function ok(expr: Expr) { | |
const content: Inner<string|number> = expr.content; | |
evaluate(content); | |
} | |
// doesn't | |
function err(expr: Expr) { | |
evaluate(expr.content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment