Skip to content

Instantly share code, notes, and snippets.

@P4
Last active December 21, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save P4/b2382153282f1f86345cb8bf3239b4f0 to your computer and use it in GitHub Desktop.
Save P4/b2382153282f1f86345cb8bf3239b4f0 to your computer and use it in GitHub Desktop.
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