2016-12-28 05:40:04 +03:00
|
|
|
exports[`test test.js 1`] = `
|
|
|
|
"/**
|
|
|
|
* Test nonstrict type param arity checking,
|
|
|
|
* as enabled by
|
|
|
|
*
|
|
|
|
* [options]
|
|
|
|
* experimental.strict_type_args=false
|
|
|
|
*
|
|
|
|
* in .flowconfig.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
// no arity error in type annotation using polymorphic class
|
|
|
|
|
|
|
|
class MyClass<T> {
|
|
|
|
x: T;
|
|
|
|
constructor(x: T) {
|
|
|
|
this.x = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var c: MyClass = new MyClass(0); // no error
|
|
|
|
|
|
|
|
// no arity error in type annotation using polymorphic class with defaulting
|
|
|
|
|
|
|
|
class MyClass2<T, U = string> {
|
|
|
|
x: T;
|
|
|
|
y: U;
|
|
|
|
constructor(x: T, y: U) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 19:56:42 +03:00
|
|
|
var c2: MyClass2 = new MyClass2(0, \"\"); // no error
|
2016-12-28 05:40:04 +03:00
|
|
|
|
|
|
|
// no arity error in type annotation using polymorphic type alias
|
|
|
|
|
|
|
|
type MyObject<T> = {
|
|
|
|
x: T;
|
|
|
|
}
|
|
|
|
|
|
|
|
var o: MyObject = { x: 0 }; // no error
|
|
|
|
|
|
|
|
// arity error in type alias rhs
|
|
|
|
|
|
|
|
type MySubobject = { y: number } & MyObject; // no error
|
|
|
|
|
|
|
|
// arity error in interface extends
|
|
|
|
|
|
|
|
interface MyInterface<T> {
|
|
|
|
x: T;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface MySubinterface extends MyInterface { // no error
|
|
|
|
y: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no arity error in extends of polymorphic class
|
|
|
|
|
|
|
|
class MySubclass extends MyClass { // ok, type arg inferred
|
|
|
|
y: number;
|
|
|
|
constructor(y: number) {
|
|
|
|
super(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no arity error in call of polymorphic function
|
|
|
|
|
|
|
|
function singleton<T>(x: T):Array<T> { return [x]; }
|
|
|
|
|
|
|
|
var num_array:Array<number> = singleton(0); // ok, type arg inferred
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
/**
|
|
|
|
* Test nonstrict type param arity checking,
|
|
|
|
* as enabled by
|
|
|
|
*
|
|
|
|
* [options]
|
|
|
|
* experimental.strict_type_args=false
|
|
|
|
*
|
|
|
|
* in .flowconfig.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-28 05:40:04 +03:00
|
|
|
// no arity error in type annotation using polymorphic class
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-28 05:40:04 +03:00
|
|
|
class MyClass<T> {
|
|
|
|
x: T;
|
|
|
|
constructor(x: T) {
|
|
|
|
this.x = x;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
var c: MyClass = new MyClass(0); // no error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// no arity error in type annotation using polymorphic class with defaulting
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2016-12-28 05:40:04 +03:00
|
|
|
class MyClass2<T, U=string> {
|
|
|
|
x: T;
|
|
|
|
y: U;
|
|
|
|
constructor(x: T, y: U) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
var c2: MyClass2 = new MyClass2(0, \"\"); // no error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// no arity error in type annotation using polymorphic type alias
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2017-01-30 20:08:55 +03:00
|
|
|
type MyObject<T> = {
|
|
|
|
x: T
|
|
|
|
};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
var o: MyObject = { x: 0 }; // no error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// arity error in type alias rhs
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
type MySubobject = { y: number } & MyObject; // no error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// arity error in interface extends
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2017-01-30 20:08:55 +03:00
|
|
|
interface MyInterface<T> {
|
|
|
|
x: T
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-30 20:08:55 +03:00
|
|
|
interface MySubinterface extends MyInterface { // no error
|
|
|
|
y: number
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// no arity error in extends of polymorphic class
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
class MySubclass
|
|
|
|
extends MyClass { // ok, type arg inferred
|
2016-12-28 05:40:04 +03:00
|
|
|
y: number;
|
|
|
|
constructor(y: number) {
|
|
|
|
super(y);
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// no arity error in call of polymorphic function
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2016-12-28 05:40:04 +03:00
|
|
|
function singleton<T>(x: T): Array<T> {
|
2017-01-24 22:38:12 +03:00
|
|
|
return [x];
|
2016-12-28 05:40:04 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 18:16:38 +03:00
|
|
|
var num_array: Array<number> = singleton(0); // ok, type arg inferred
|
|
|
|
"
|
2016-12-28 05:40:04 +03:00
|
|
|
`;
|