-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Flow type workers #4903
Flow type workers #4903
Conversation
9adfa41
to
b59c4a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 this is so great.
*/ | ||
constructor(coord, size, sourceMaxZoom) { | ||
constructor(coord: any, size: number, sourceMaxZoom: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be coord: TileCoord
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a rough pass; for many types I just used any
where flow would otherwise complain. tile_coord.js
hasn't been typed yet.
src/source/tile.js
Outdated
this.state = 'loading'; | ||
|
||
this.placementThrottler = new Throttler(300, this._immediateRedoPlacement.bind(this)); | ||
} | ||
|
||
registerFadeDuration(animationLoop, duration) { | ||
registerFadeDuration(animationLoop: any, duration: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not duration: number
?
src/source/worker.js
Outdated
workerSources: { [string]: { [string]: WorkerSource } }; | ||
|
||
constructor(self: WorkerGlobalScope) { | ||
this.self = (self: any); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I don't see a cleaner way to do this. Could we stick a //
comment here explaining the cast to any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, would be nice if Object.assign(self, {registerWorkerSource: ..., registerRTLTextPlugin: ...})
worked, but it doesn't. I'll comment.
src/symbol/collision_tile.js
Outdated
@@ -91,7 +119,7 @@ class CollisionTile { | |||
]; | |||
} | |||
|
|||
serialize(transferables) { | |||
serialize(transferables /*: ?Array<Transferable> */): SerializedCollisionTile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a comment for the parameter type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oversight.
This adds flow annotations to the majority of the
Worker
-related code. I started on #4876, wanted to make some refactors, and realized that it would be better to have the safety of some static type checking as I did.The first commit here switches the eslint
sourceType
option tomodule
, so that we can use module types without resorting to flow comments.Q: Why not use flow comments?
A: They're ugly, and they're not as good as native type annotations: not syntax highlighted, not linted (e.g. no warnings if you import something and don't use it), no documentation.js support, no IDE integration.
Q: What are the side effects of
"sourceType": "module"
?A: AFAICT, it doesn't force us to actually use non-type
import
/export
rather than CommonJSrequire
, it just means that we can't'use strict'
in each file -- this is enforced by eslint because modules are always strict. I worked around this by writing a simplestrictify
transform that puts them back in. (I didn't use the published one because it's buggy and unmaintained.)Q: Shouldn't you be able to use
import type
without requiring"sourceType": "module"
?A: Yes, I think you should be. If you agree, 👍 this bug.
Beyond that, the eslint + flow combo pretty much works. The only issue I've found is that eslint chokes on unnamed parameters in function types. So just name them:
Works
Doesn't Work