-
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: $Record types were experimental, and kind of rotting as a third object-like def type besides ObjT and InstanceT. It turns out that its functionality can be covered by $Enum and dict types. So there is no use for it. In fact, using $Enum and dict types, you can get better $Record types because you can also specify the value type! Also simplified type of propTypes to Object. With this diff we could replace it with $Subtype<{[key: $Enum<P>]: any]}>. But in a follow-up diff, we're going to make propTypes allow spreads etc. which may interfere with such a type. Moving forward ES6 React doesn't have a good story around propTypes anyway, and for legacy React that annotation is not even touched, so Object should really be enough. Reviewed By: @mroch Differential Revision: D2132989
- Loading branch information
1 parent
f4178d5
commit 6d4447b
Showing
8 changed files
with
41 additions
and
56 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
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
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,18 @@ | ||
|
||
test.js:4:8,9: string | ||
This type is incompatible with | ||
test.js:2:23,28: number | ||
|
||
test.js:7:1,6: property name "qux" is a string | ||
This type is incompatible with | ||
test.js:1:13,25: union type | ||
|
||
test.js:13:1,6: string literal qux | ||
Property not found in | ||
test.js:9:10,29: object type | ||
|
||
test.js:19:6,34: string literal qux | ||
Property not found in | ||
test.js:18:19,44: object type | ||
|
||
Found 4 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,20 @@ | ||
type Key1 = 'foo' | 'bar'; // make an enum type with known key set | ||
var o1: {[key: Key1]: number} = { | ||
foo: 0, | ||
bar: "", // error: string ~/~ number | ||
}; | ||
o1.foo; // OK | ||
o1.qux; // error: qux not found | ||
|
||
type R = {foo: any, bar: any}; | ||
type Key2 = $Enum<R>; // another way to make an enum type, with unknown key set | ||
var o2: {[key: Key2]: number} = { foo: 0 }; // OK to leave out bar | ||
o2.bar; // OK to access bar | ||
o2.qux; // error: qux not found | ||
|
||
class C<X> { | ||
x: $Subtype<{[key: $Enum<X>]: any}>; // object with larger key set than X's | ||
} | ||
class D extends C<{foo: number, bar: string}> { | ||
x: { foo: number, qux: boolean }; // error: qux not found | ||
} |