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

_TypeError (type 'Uint8List' is not a subtype of type 'Never' of 'k') #122

Open
huzaifansari54 opened this issue Mar 6, 2023 · 2 comments

Comments

@huzaifansari54
Copy link

@spebbe
hello i want to create Imap of <Unit8List ,XFile > i kindly help me out
error

@huzaifansari54 huzaifansari54 changed the title i dont know this show me this erro_TypeError (type 'Uint8List' is not a subtype of type 'Never' of 'k') _TypeError (type 'Uint8List' is not a subtype of type 'Never' of 'k') Mar 6, 2023
@tcmhoang
Copy link

In order to create IMap<K,V> using imap function, the key's type must extend Comparable. And Uint8List type does not satisfy this condition.

And you may wonder why the compiler did not catch this error before running. The reason is that you gave the type signature of both key and value pair in the variable definition, so the compiler infers the right expression's type. So it casts the rights' expression type from <dynamic,dynamic> to be the exact same specified type in signature. In your case, it will be <Uint8List,XFile>.

It cast in the runtime rather than complied time due to the nature of the comparableOrder function implementation which is used in imap function. It does not force you to specify the A type in the Comparable<A> type, again it will be Compable<dynamic> and it will be cast down during runtime. First, it will happily create an instance of this type for you, but later errors will definitely occur when interacting with the instance of this type.

Also, the IMap type definition does not enforce this kind of constrain. Because it assumes you specify the order when you're creating an instance of IMap

In order to achieve what you want, you need to use the constructor of IMap and explicitly specify the Order of the key in IMap.

You may implement something like this.

IMap<Uint8List, dynamic> a = IMap.empty(
    orderBy(IntOrder, (a) => a.hashCode),
);

@huzaifansari54
Copy link
Author

thanks sir

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