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

arguments in combiner need type info #7

Open
mikew opened this issue Jan 4, 2019 · 1 comment
Open

arguments in combiner need type info #7

mikew opened this issue Jan 4, 2019 · 1 comment

Comments

@mikew
Copy link

mikew commented Jan 4, 2019

I'm new to Dart, so this could be just a language quirk, but the examples in the readme don't provide give any type info to the arguments in the combiner function. When doing that, they're actually dynamic, inference doesn't work.

Given this:

class ExampleState {
  String firstName;
  String age;
}

final getFirstName = (ExampleState state) => state.firstName;
final getAge = (ExampleState state) => state.age;

Here is what the readme says to do:

final exampleSelector = createSelector2(
  getFirstName,
  getAge,
  (firstName, age) => '$firstName $age',
);

But firstName and age are dynamic, providing type info works but results in duplication:

final exampleSelector = createSelector2(
  getFirstName,
  getAge,
  (String firstName, int age) => '$firstName $age',
);

What's worse is when you give the wrong type info, Dart suddenly smartens up and says it can't happen:

final exampleSelector = createSelector2(
  getFirstName,
  getAge,
  (String firstName, String age) => '$firstName $age',
);

yields:

Couldn't infer type parameter 'R2'.

Tried to infer 'int' for 'R2' which doesn't work:
  Parameter 'combiner' declared as     '(R1, R2) → T'
                       but argument is '(String, String) → String'.
The type 'int' was inferred from:
  Parameter 'selector2' declared as     '(S) → R2'
                        but argument is '(ExampleState) → int'.

Consider passing explicit type argument(s) to the generic.
dart(strong_mode_could_not_infer)

Could this have something to do with my analysis_options.yaml file? Or is Dart's inference nowhere near the level in TypeScript?

@NicolasCharpentier
Copy link

Hey @mikew I'm like you at the time, new to Dart. Two years later this issue has not been treated and also bothers me, but it does not look like it can be fixed.

See dart-lang/sdk#34408 where it seems like Dart team won't fix that soonly.

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

2 participants