Skip to content

Cannot use int type with the sortedBy API #669

Closed
@etiennestuder

Description

@etiennestuder

Using Dart 3.2.4 and the collections package, and writing the code below...

['alpha','beta'].sortedBy((element) => element.length);

I get the error printed below:

Error: Inferred type argument 'int' doesn't conform to the bound 'Comparable<K>' of the type variable 'K' on 'IterableExtension|sortedBy'.
 - 'Comparable' is from 'dart:core'.
Try specifying type arguments explicitly so that they conform to the bounds.
    var xx = ['alpha','beta'].sortedBy((element) => element.length);

Does it mean that int does not implement Comparable?
I did not know how to apply the advice given in the error message.

I'm not a Dart expert, and it is unclear to me whether sorting by a criteria of type int is not supported by design when using the sortedBy API, or if I'm doing something wrong, or if there is an issue in the library.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions