-
Notifications
You must be signed in to change notification settings - Fork 1
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
Circular dependencies, recursive types and type spreading #2
Comments
We can turn off that warning locally in the file(s) as needed: @@warning("-30")
type rec node = {ownerDocument: Null.t<document>}
and document = {ownerDocument: Null.t<document>}
and window = {document: document} This yields no warning. So that would be an acceptable approach still I think. But, it'd be good to only duplicate props only when needed, and still spread them when we're not in a recursive chain. |
The file is here now: https://github.com/rescript-lang/rescript-compiler/blob/master/runtime/Dom.res |
Thanks for pointing that out. I believe we will need an initial chain of recursive types where we repeat the properties. Once we have those, we can have some edge types which can use spreading. |
Sounds like a good approach! |
Alright, when it comes to the interfaces I believe we have three categories: the precursors, the chain and the spreaders. The precursors are interfaces which are used in the chain and need to be defined first. Examples:
Then there is a chain of recursive types (which thus cannot use spreading) Examples:
The chain has circular dependencies and needs to copy all properties of its base interfaces. Example:
|
One question that comes to mind - do we have circular dependencies in the spreads too? Or is the problem mainly that spreads, as of now, simply aren't allowed in recursive definitions? If it's the latter, one could look into what it'd take to allow spreading in recursive definitions in the compiler, provided we can find a way to error out if the spread happens to be circular. |
Good point, I would need to check that. |
I think it would be pretty interesting to just describe what ideal typing for DOM would look like, to begin with, and separately check what is supported today and what might be needed in terms of extensions. |
It appears that https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet and https://developer.mozilla.org/en-US/docs/Web/API/CSSRule have a nested thing going on. This is not necessarily a problem, it might be fine to have multiple chains that need to be emitted in order. |
As most of us, may have somewhat expected, the DOM has cyclic dependencies between types.
Example case:
Types
Window
,Document
andNode
.The property window.document means
type document
needs to be known beforetype window
.Document inherits from Node, so
Node
needs to be known toDocument
to be able to spread.Node.ownerDocument returns a
document
fromnode
thus creating a loop.Spreading does not work here and duplicating the properties leads to
It is my understanding that https://github.com/TheSpyder/rescript-webapi uses all the types defined in
node_modules/rescript/lib/ocaml/dom.ml
, I can no longer find this file in the current ReScript compiler though. It is my understanding that we also no longer what to use that.Anyway, feels like back to the drawing board.
Suggestions to model this are welcome!
The text was updated successfully, but these errors were encountered: