Skip to content
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

A subtype in a list is not a subtype? #6136

Closed
sharno opened this issue Apr 12, 2018 · 4 comments
Closed

A subtype in a list is not a subtype? #6136

sharno opened this issue Apr 12, 2018 · 4 comments

Comments

@sharno
Copy link

sharno commented Apr 12, 2018

According to the Subtypes page in Flow documentation about Subtypes, that works fine:

type A = {+id: number}
type B = {+id: number, +text: string}

const b : B = {id: 1, text: "hello"}
const a : A = b

but why when we put the types in a list it loses the property of being a subtype?

type A = {+id: number}[]
type B = {+id: number, +text: string}[]

const b : B = [{id: 1, text: "hello"}]
const a : A = b

And is there a cleaner way of solving such an issue if I want to pass B as an array to a function that takes A as an array without casting to any first?

https://flow.org/try/#0C4TwDgpgBAglC8UDeBqAlgEwFxQHYFcBbAIwgCcBfAbQF0AoUSKAIQWXWzyNLIBooUwCAA9gOAM7AyaXAHNq9OgGMA9rklRiUHK0RUkmHAEZ+Q0TgBEACwgAbWyosV6q9cCgBDbbDbE6QA

@apsavin
Copy link
Contributor

apsavin commented Apr 12, 2018

@TrySound
Copy link
Contributor

This probably can be closed.
/cc @vkurchatkin

@sharno
Copy link
Author

sharno commented Apr 12, 2018

Thanks!
Is there an issue tracking the $ReadOnlyArray getting documented? As it's not in the documentation yet

@apsavin
Copy link
Contributor

apsavin commented Apr 12, 2018

#2464

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants