* Extract custom tests from tests/flow/
Approach:
1. Remove all .js files in tests/flow except .snap.js files.
2. Copy over all .js files from tests/ in the flow repo.
3. Go through the diff looking for deletions.
- It was easy to see which deletions were due to changes in the tests
due to updates in the flow repo.
- For the rest of the deletions, I used `git blame` to verify that
they had been added by us since the flow tests were copied over.
This makes tests/flow/ simply a copy of the tests from the flow repo,
making it easier to sync with the upstream flow tests in the future.
* Add a script for syncing the flow tests
* Sync the flow tests
73 lines
2.3 KiB
JavaScript
73 lines
2.3 KiB
JavaScript
// @flow
|
|
|
|
class Base {
|
|
unannotatedField;
|
|
annotatedField: number;
|
|
initializedField = 42;
|
|
initializedFieldWithThis = this.initializedField;
|
|
annotatedInitializedFieldValid: ?number = 42;
|
|
annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
|
|
|
|
static unannotatedField;
|
|
static annotatedField: number;
|
|
static initializedField = 'asdf';
|
|
static initializedFieldWithThis = this.initializedField;
|
|
static annotatedInitializedFieldValid: ?number = 42;
|
|
static annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
|
|
}
|
|
|
|
var o = new Base();
|
|
|
|
/**
|
|
* Unannotated fields are open.
|
|
*/
|
|
(o.unannotatedField: string);
|
|
(o.unannotatedField: number);
|
|
(Base.unannotatedField: string);
|
|
(Base.unannotatedField: number);
|
|
|
|
/**
|
|
* Annotated (but uninitialized) fields still have a type.
|
|
*/
|
|
(o.annotatedField: number);
|
|
(o.annotatedField: string); // Error: number ~> string
|
|
(Base.annotatedField: number);
|
|
(Base.annotatedField: string); // Error: number ~> string
|
|
|
|
/**
|
|
* Initialized (but unannotated) fields assume the type of their initializer.
|
|
*/
|
|
(o.initializedField: number);
|
|
(o.initializedField: string); // Error: number ~> string
|
|
(Base.initializedField: string);
|
|
(Base.initializedField: number); // Error: string ~> number
|
|
|
|
/**
|
|
* Initialized fields can reference `this`.
|
|
*/
|
|
(o.initializedFieldWithThis: number);
|
|
(o.initializedFieldWithThis: string); // Error: number ~> string
|
|
(Base.initializedFieldWithThis: string);
|
|
(Base.initializedFieldWithThis: number); // Error: string ~> number
|
|
|
|
/**
|
|
* Initialized + annotated fields take the type of the annotation.
|
|
* (Note that this matters when the annotation is more general than the type of
|
|
* the initializer)
|
|
*/
|
|
(o.annotatedInitializedFieldValid: ?number);
|
|
(o.annotatedInitializedFieldValid: number); // Error: ?number ~> number
|
|
(Base.annotatedInitializedFieldValid: ?number);
|
|
(Base.annotatedInitializedFieldValid: number); // Error: ?number ~> number
|
|
|
|
/**
|
|
* Initialized + annotated fields where the init/annot combo is a mismatch
|
|
* should assume the type of the annotation.
|
|
*
|
|
* (This happens in addition to erroring at the site of initialization)
|
|
*/
|
|
(o.annotatedInitializedFieldInvalid: number);
|
|
(o.annotatedInitializedFieldInvalid: string); // Error: number ~> string
|
|
(Base.annotatedInitializedFieldInvalid: number);
|
|
(Base.annotatedInitializedFieldInvalid: string); // Error: number ~> string
|