Skip to content

Commit

Permalink
add use-case: type substraction / assertion (!)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra committed Sep 9, 2017
1 parent 28aece0 commit 4d14c9f
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 172 deletions.
12 changes: 10 additions & 2 deletions tests/baselines/reference/typeCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ let strBool: isBool(string); // 0
let anyBool: isBool(any); // 0
let neverBool: isBool(never); // 0

type Assert<T> = (<U>(v: U | null | undefined) => U)(T);
let assert: Assert<string | undefined>; // string

type Minus<A, B> = (<U>(v: U | B) => U)(A);
let noNumbers: Minus<string | number, number>; // string

interface ObjectHasStringIndex {
// <T extends { [k: string]: any }>(o: T): T[string];
(o: { [k: string]: any }): '1';
Expand Down Expand Up @@ -152,8 +158,8 @@ type T19 = Strip2<() => Obj>; // fails, unresolved, want { x: number, z: { kind:

let a1: () => string;
let b1: typeof a1();
type Assert<T extends () => any> = T();
let c1: Assert<typeof a1>;
type Abc<T extends () => any> = T();
let c1: Abc<typeof a1>;

declare function infer1<T extends () => any>(x: T): T();
infer1(null! as () => number);
Expand Down Expand Up @@ -221,6 +227,8 @@ var trueBool; // 1
var strBool; // 0
var anyBool; // 0
var neverBool; // 0
var assert; // string
var noNumbers; // string
var ObjectHasStringIndexTestT; // '1'
var ObjectHasStringIndexTestF; // wanted '0', got '1'... so can't match for index, and erroring RHS yields `any`. ouch.
var a1;
Expand Down
Loading

0 comments on commit 4d14c9f

Please sign in to comment.