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

UIP-2024 Support covariant props #49

Closed
greglittlefield-wf opened this issue Feb 15, 2017 · 1 comment
Closed

UIP-2024 Support covariant props #49

greglittlefield-wf opened this issue Feb 15, 2017 · 1 comment

Comments

@greglittlefield-wf
Copy link
Contributor

greglittlefield-wf commented Feb 15, 2017

Dart 1.22 recently added support for covariant overrides, which allows for sound tightening of method argument types.

This applies to fields/setters as well.

Currently, you cannot tighten the type of a prop in strong mode.

class FooProps {
  Iterable items;
}

class BarProps extends FooProps {
  @override
  List items; // Error: Field declaration FooProps.items cannot be overridden in BarProps.
}

However, with covariant, that should now be possible:

class FooProps {
  covariant Iterable items;
}

class BarProps extends FooProps {
  @override
  List items;
}

The transformer needs to be updated to generate setters with the covariant keyword when necessary.

-covariant Iterable items;
+Iterable get items => props[...];
+set items(covariant Iterable value) => props[...] = value;

Also worth noting:

In cases where the supertype authors did not foresee this need, it is still possible to tighten a parameter type by putting the covariant modifier on the overriding parameter declaration.

@rmconsole-wf
Copy link

It looks like you have not included any tickets in the title of this issue. Please create a ticket for this issue, or click here to have Rosie create one for you.

@rmconsole-wf rmconsole-wf changed the title Support covariant props UIP-2024 Support covariant props Feb 15, 2017
greglittlefield-wf pushed a commit that referenced this issue Jun 19, 2020
Pull in tryCast and other utils from over_react, add allDescendants util
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants