-
Notifications
You must be signed in to change notification settings - Fork 15
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
Best method to convert Lists? #180
Comments
You can cast types such as |
Oh no, don't do this! :) This isn't platform-consistent as
For brevity, I prefer 1 and 3, but 2 makes sense in cases where you know that the list is of one type and might be an expensive type to do extension on List<int> {
JSArray<JSNumber> toJS => this.map((e) => e.toJS).toList().toJS();
}
extension on List<String> {
JSArray<JSNumber> toJS => this.map((e) => e.toJS).toList().toJS();
} but maybe doing it for just primitives tackles the common case. A downside is that this might encourage slightly slower code like Hope that helps! |
I had also tried Btw, anything wrong with window.navigator.vibrate([400] as VibratePattern); in this case? |
Yes, for a similar reason as above around casting Dart types to a JS types ( |
I use unsafe casts a lot. Encountered that while trying to compile to WASM module. |
Yeah, and I can totally see why users reach for casts since the language doesn't tell you that isn't okay, which is why I want that lint above. |
I'm guessing this isn't a bug, so was more wondering what the recommendation would be with the following:
yields
error: The argument type 'List<int>' can't be assigned to the parameter type 'JSAny'. (argument_type_not_assignable at [web_test] web/main.dart:4)
It seems Lists of primitives are not automatically handled. Should we:
window.navigator.vibrate([400] as VibratePattern);
window.navigator.vibrate([400].jsify()!);
?
The text was updated successfully, but these errors were encountered: