Update keyof tests to reflect #12425

Removes number from all the keyof types, and adds a test that numeric
indexes are ignored.
This commit is contained in:
Ethan Resnick 2016-11-28 04:21:33 -08:00
parent 88b7d53978
commit 8b7252c4b0
4 changed files with 482 additions and 449 deletions

View File

@ -21,11 +21,12 @@ class Options {
}
type Dictionary<T> = { [x: string]: T };
type NumericallyIndexed<T> = { [x: number]: T };
const enum E { A, B, C }
type K00 = keyof any; // string | number
type K01 = keyof string; // number | "toString" | "charAt" | ...
type K00 = keyof any; // string
type K01 = keyof string; // "toString" | "charAt" | ...
type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ...
type K03 = keyof boolean; // "valueOf"
type K04 = keyof void; // never
@ -34,19 +35,20 @@ type K06 = keyof null; // never
type K07 = keyof never; // never
type K10 = keyof Shape; // "name" | "width" | "height" | "visible"
type K11 = keyof Shape[]; // number | "length" | "toString" | ...
type K12 = keyof Dictionary<Shape>; // string | number
type K11 = keyof Shape[]; // "length" | "toString" | ...
type K12 = keyof Dictionary<Shape>; // string
type K13 = keyof {}; // never
type K14 = keyof Object; // "constructor" | "toString" | ...
type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ...
type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ...
type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ...
type K17 = keyof (Shape | Item); // "name"
type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price"
type K19 = keyof NumericallyIndexed<Shape> // never
type KeyOf<T> = keyof T;
type K20 = KeyOf<Shape>; // "name" | "width" | "height" | "visible"
type K21 = KeyOf<Dictionary<Shape>>; // string | number
type K21 = KeyOf<Dictionary<Shape>>; // string
type NAME = "name";
type WIDTH_OR_HEIGHT = "width" | "height";
@ -247,7 +249,8 @@ class OtherPerson {
getParts() {
return getProperty(this, "parts")
}
}
}
//// [keyofAndIndexedAccess.js]
var __extends = (this && this.__extends) || function (d, b) {
@ -449,6 +452,9 @@ declare class Options {
declare type Dictionary<T> = {
[x: string]: T;
};
declare type NumericallyIndexed<T> = {
[x: number]: T;
};
declare const enum E {
A = 0,
B = 1,
@ -471,6 +477,7 @@ declare type K15 = keyof E;
declare type K16 = keyof [string, number];
declare type K17 = keyof (Shape | Item);
declare type K18 = keyof (Shape & Item);
declare type K19 = keyof NumericallyIndexed<Shape>;
declare type KeyOf<T> = keyof T;
declare type K20 = KeyOf<Shape>;
declare type K21 = KeyOf<Dictionary<Shape>>;

File diff suppressed because it is too large Load Diff

View File

@ -47,16 +47,22 @@ type Dictionary<T> = { [x: string]: T };
>x : string
>T : T
type NumericallyIndexed<T> = { [x: number]: T };
>NumericallyIndexed : NumericallyIndexed<T>
>T : T
>x : number
>T : T
const enum E { A, B, C }
>E : E
>A : E.A
>B : E.B
>C : E.C
type K00 = keyof any; // string | number
type K00 = keyof any; // string
>K00 : string
type K01 = keyof string; // number | "toString" | "charAt" | ...
type K01 = keyof string; // "toString" | "charAt" | ...
>K01 : "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf"
type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ...
@ -82,11 +88,11 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible"
>K10 : "name" | "width" | "height" | "visible"
>Shape : Shape
type K11 = keyof Shape[]; // number | "length" | "toString" | ...
type K11 = keyof Shape[]; // "length" | "toString" | ...
>K11 : "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight"
>Shape : Shape
type K12 = keyof Dictionary<Shape>; // string | number
type K12 = keyof Dictionary<Shape>; // string
>K12 : string
>Dictionary : Dictionary<T>
>Shape : Shape
@ -102,7 +108,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ...
>K15 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision"
>E : E
type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ...
type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ...
>K16 : "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight"
type K17 = keyof (Shape | Item); // "name"
@ -115,6 +121,11 @@ type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "
>Shape : Shape
>Item : Item
type K19 = keyof NumericallyIndexed<Shape> // never
>K19 : never
>NumericallyIndexed : NumericallyIndexed<T>
>Shape : Shape
type KeyOf<T> = keyof T;
>KeyOf : keyof T
>T : T
@ -125,7 +136,7 @@ type K20 = KeyOf<Shape>; // "name" | "width" | "height" | "visible"
>KeyOf : keyof T
>Shape : Shape
type K21 = KeyOf<Dictionary<Shape>>; // string | number
type K21 = KeyOf<Dictionary<Shape>>; // string
>K21 : string
>KeyOf : keyof T
>Dictionary : Dictionary<T>
@ -970,3 +981,4 @@ class OtherPerson {
>"parts" : "parts"
}
}

View File

@ -21,11 +21,12 @@ class Options {
}
type Dictionary<T> = { [x: string]: T };
type NumericallyIndexed<T> = { [x: number]: T };
const enum E { A, B, C }
type K00 = keyof any; // string | number
type K01 = keyof string; // number | "toString" | "charAt" | ...
type K00 = keyof any; // string
type K01 = keyof string; // "toString" | "charAt" | ...
type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ...
type K03 = keyof boolean; // "valueOf"
type K04 = keyof void; // never
@ -34,19 +35,20 @@ type K06 = keyof null; // never
type K07 = keyof never; // never
type K10 = keyof Shape; // "name" | "width" | "height" | "visible"
type K11 = keyof Shape[]; // number | "length" | "toString" | ...
type K12 = keyof Dictionary<Shape>; // string | number
type K11 = keyof Shape[]; // "length" | "toString" | ...
type K12 = keyof Dictionary<Shape>; // string
type K13 = keyof {}; // never
type K14 = keyof Object; // "constructor" | "toString" | ...
type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ...
type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ...
type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ...
type K17 = keyof (Shape | Item); // "name"
type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price"
type K19 = keyof NumericallyIndexed<Shape> // never
type KeyOf<T> = keyof T;
type K20 = KeyOf<Shape>; // "name" | "width" | "height" | "visible"
type K21 = KeyOf<Dictionary<Shape>>; // string | number
type K21 = KeyOf<Dictionary<Shape>>; // string
type NAME = "name";
type WIDTH_OR_HEIGHT = "width" | "height";
@ -247,4 +249,4 @@ class OtherPerson {
getParts() {
return getProperty(this, "parts")
}
}
}