Stole all of Nathan's tests.

This commit is contained in:
Daniel Rosenwasser 2016-08-25 12:11:06 -07:00
parent bab4a52983
commit 7e4715dfdc
3 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,10 @@
// @strictNullChecks: true
interface X {
n: number
}
class C implements X { // error, n: undefined isn't assignable to n: number
n = undefined;
}
class C2 implements X {
n = null;
}

View File

@ -0,0 +1,72 @@
// @noImplicitAny: true
interface Event {
time: number;
}
interface Base {
superHandle: (e: Event) => number;
}
interface Listener extends Base {
handle: (e: Event) => void;
}
interface Ringer {
ring: (times: number) => void;
}
interface StringLiteral {
literal(): "A";
literals: "A" | "B";
}
abstract class Watcher {
abstract watch(e: Event): number;
}
class Alarm extends Watcher implements Listener, Ringer, StringLiteral {
str: string;
handle = e => {
this.str = e.time; // error
}
superHandle = e => {
this.str = e.time; // error
return e.time;
}
ring(times) {
this.str = times; // error
}
watch(e) {
this.str = e.time; // error
return e.time;
}
literal() {
return "A"; // ok: "A" is assignable to "A"
}
literals = "A"; // ok: "A" is assignable to "A" | "B"
}
interface A {
p: string;
q(n: string): void;
r: string;
s: string;
}
interface B {
p: number;
q(n: number): void;
r: boolean;
s: string;
}
class C {
r: number;
}
class Multiple extends C implements A, B {
p = undefined; // error, Multiple.p is implicitly any because A.p and B.p exist
q(n) { // error, n is implicitly any because A.q and B.q exist
n.length;
n.toFixed;
}
r = null; // OK, C.r wins over A.r and B.r
s = null; // OK, A.s and B.s match
}
let multiple = new Multiple();
multiple.r.toFixed; // OK, C.r wins so Multiple.r: number
multiple.r.length; // error, Multiple.r: number
multiple.s.length; // OK, A.s and B.s match.

View File

@ -0,0 +1,23 @@
interface Long {
length: number;
}
interface Lol {
canhaz: string;
}
interface Ceiling {
location: { [coordinates: string]: [number, number] };
}
interface Invisible {
invisibles: string[];
}
class Cat implements Long, Lol, Ceiling, Invisible {
length = undefined;
canhaz = null;
location = {};
invisibles = [];
}
const lolCat = new Cat();
lolCat.length = "wat";
lolCat.canhaz = false;
lolCat.location['ceiling'] = -1;
lolCat.invisibles.push(0);