-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Number literal object keys typechecking #7593
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e6a1103
[typing] Add number literal keys
goodmind 5aa2e15
[tests] Update object tests
goodmind 6451306
[tests] Add subsequent object key definition tests
goodmind 6a1e2ac
[typing] Check own props then fallback to dict
goodmind cc21649
[tests] update dictionary tests
goodmind be8e863
[js] Add js_of_ocaml functionality
goodmind b9b62a6
[typing] Add NamedNum constructor
goodmind f259218
[typing] Flow tuples to numerical objects
goodmind 575d803
[tests] Add numeric keys indexer test
goodmind 4a82d8d
[js] Remove custom dtoa
goodmind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,61 @@ | ||
//@flow | ||
|
||
// No indexer should be fine | ||
function foo0(): {} { | ||
return { foo: "bar" } | ||
return { foo: "bar" }; | ||
} | ||
|
||
// Matching indexer should be fine | ||
function foo1(): {[key: string]: string} { | ||
return { foo: "bar" } | ||
function foo1(): { [key: string]: string } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// Indexer with different key type is an error when it matches | ||
function foo2(): {[key: number]: string} { | ||
return { foo: "bar" } | ||
function foo2(): { [key: number]: string } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// Matching indexer with different value type is an error | ||
function foo3(): {[key: string]: number} { | ||
return { foo: "bar" } | ||
function foo3(): { [key: string]: number } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// Indexer with different key type and different value type is twice an error | ||
function foo4(): {[key: number]: number} { | ||
return { foo: "bar" } | ||
function foo4(): { [key: number]: number } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// If key exists in object type then indexer is not matched | ||
function foo5(): {[key: string]: number; foo: string} { | ||
return { foo: "bar" } | ||
function foo5(): { [key: string]: number, foo: string } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// If key exists in object type then indexer is not matched | ||
function foo6(): {[key: number]: number; foo: string} { | ||
return { foo: "bar" } | ||
function foo6(): { [key: number]: number, foo: string } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// Should still complain about mistyped properties | ||
function foo7(): {[key: string]: number; foo: number} { | ||
return { foo: "bar" } | ||
function foo7(): { [key: string]: number, foo: number } { | ||
return { foo: "bar" }; | ||
} | ||
|
||
// TODO: ok | ||
function foo8(): { [key: number]: string } { | ||
return { 0: "bar" }; | ||
} | ||
|
||
// TODO: error | ||
function foo9(): { [key: string]: string } { | ||
return { 0: "bar" }; | ||
} | ||
|
||
// TODO: error | ||
function foo9(): { [key: string]: string } { | ||
return { 0: "bar" }; | ||
} | ||
|
||
// TODO: ok | ||
function foo10(): { [key: string | number]: string } { | ||
return { 1: "nice", a: "wtf" }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this broke
{[key: number]: any}
reads,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this #2293 (comment) applies to this also, so probably I fixed it wrong