-
Notifications
You must be signed in to change notification settings - Fork 28
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
docs request: help me figure out what to do with JS unions when they occur #337
Comments
I like that idea! A simple doc comment illustrating that this is a typedef that represents a union of There's a general section on type-checking in the docs with JS interop, but we can always improve it: https://dart.dev/interop/js-interop/js-types#compatibility-type-checks-and-casts. Maybe we can add a comment saying to use |
Thanks, @srujzs. If I don't do the |
Kevin is right that you can't use One thing we need to watch out for when generating these docs is accidentally telling users to use |
Oh my. All the more reason to generate the docs and sample code to let folks know how to access the objects properly. As it is, we only have you and Kevin. : ) |
As an example, the docs for
ReadableStream.getReader()
says that it returns aReadableStreamReader
. Cool.Except the docs for
ReadableStreamReader
says that it's just aJSObject
.Now what am I supposed to do?
After talking to @kevmoo, I learned that this happens when there's a JS union, which Dart doesn't support. Fair enough. I also learned that the MDN docs for
getReader()
tell me that the possible JS returns areReadableStreamDefaultReader
orReadableStreamBYOBReader
, both of which have Dart equivalents. However neither of these types is mentioned in the Dart webgetReader()
docs or theReadableStreamReader
docs, so how do I know that if I don't talk to Kevin?With this info, my first thought is to do a Dart cast to
ReadableStreamDefaultReader
(the default) but according to Kevin, I'm not supposed to do that either. Apparently there's some lint that tells me what to do. Which is great, if I've got that lint enabled.But even if I do have that lint enabled, the docs should tell me not to waste my time on Dart
as
oris
to learn from the lint (if I have it enabled) what the right thing to do is.The MDN docs tell me what the right thing to do is. And it's my understanding that the Dart docs are generated from the MDN docs (or the same metadata that the MDN docs are generated from). So can we please make the Dart docs tell me what the right thing to do in the face of a JS union is?
Thank you. And thank you for attending my Ted talk.
The text was updated successfully, but these errors were encountered: