-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: It was not really possible to annotate ES3 functions that act like ES6 classes. This diff implements some functionality that provides a way to do that. Reviewed By: @jeffmo Differential Revision: D2152762
- Loading branch information
1 parent
c0d352d
commit 618186a
Showing
9 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
declare class C { | ||
x: number; | ||
|
||
} | ||
declare class D extends C { | ||
y: string; | ||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ declare class Color { | |
static R : number; | ||
static G : number; | ||
static B : number; | ||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ declare module M { | |
declare var x: number; | ||
declare class C { | ||
y: typeof x; | ||
|
||
} | ||
} | ||
|
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
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
constructors.js:2:1,4:1: property m | ||
Property not found in | ||
constructors.js:18:28,31: IFoo | ||
|
||
constructors.js:3:3,12: assignment of property x | ||
Error: | ||
constructors.js:3:12,12: number | ||
This type is incompatible with | ||
constructors.js:14:6,12: boolean | ||
|
||
constructors.js:3:12,12: number | ||
This type is incompatible with | ||
test.js:2:8,13: string | ||
|
||
constructors.js:5:9,9: number | ||
This type is incompatible with | ||
constructors.js:16:13,19: boolean | ||
|
||
constructors.js:16:13,19: boolean | ||
This type is incompatible with | ||
test.js:3:8,13: string | ||
|
||
test.js:4:17,29: call of method m | ||
Error: | ||
constructors.js:6:32,32: number | ||
This type is incompatible with | ||
test.js:4:8,13: string | ||
|
||
test.js:7:18,29: property x | ||
Error: | ||
constructors.js:14:6,12: boolean | ||
This type is incompatible with | ||
test.js:7:9,14: string | ||
|
||
test.js:8:18,23: property y | ||
Error: | ||
constructors.js:16:13,19: boolean | ||
This type is incompatible with | ||
test.js:8:9,14: string | ||
|
||
test.js:9:18,31: call of method m | ||
Property not found in | ||
constructors.js:18:28,31: IFoo | ||
|
||
Found 9 errors |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Foo is a class-like function | ||
function Foo() { | ||
this.x = 0; // constructs objects with property x | ||
} | ||
Foo.y = 0; // has static property y | ||
Foo.prototype = { m() { return 0; } }; | ||
|
||
// exporting Foo directly often works | ||
exports.Foo = Foo; | ||
|
||
// but sometimes, you want to type Foo | ||
// you could declare Foo as a class | ||
declare class IFoo { | ||
x: boolean; // error, should have declared x: number instead | ||
static (): void; | ||
static y: boolean; // error, should have declared static y: number instead | ||
} | ||
exports.Foo2 = (Foo: Class<IFoo>); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var Foo = require('./constructors').Foo; | ||
var x: string = new Foo().x; // error, found number instead of string | ||
var y: string = Foo.y; // error, found number instead of string | ||
var z: string = new Foo().m(); | ||
|
||
var Foo2 = require('./constructors').Foo2; | ||
var x2: string = new Foo2().x; // error, found boolean instead of string | ||
var y2: string = Foo2.y; // error, found boolean instead of string | ||
var z2: string = new Foo2().m(); |