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
Guidance on fixing TypeScript type-definitions #16264
Comments
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. To help make it easier for us to investigate your issue, please follow the contributing guidelines. |
Whats even more funny, providing only |
What version of Electron are you trying this with? The ability to use
Yep, you're on track. The npm script
where
I don't think, as of yet, we've run into a situation like this where we've wanted to use a union or generic or similar in the definitions (although that could be due only to oversight). The fact that the docs are in JS and we generate TS definitions limits us unless we change something I think, but any changes you'd want to make to anything other than the docs would likely live in the electron-typescript-definitions module. I'm open to thoughts from you or others on the best way to tackle this! |
If we were writing the definitions in plain typescript you are correct @zewa666 we would use The way we would do this with our current auto-generation set up is either declare those properties as optional in markdown in a new PartialRectangle structure. E.g. #### `win.setBounds(bounds[, animate])`
* `bounds` [PartialRectangle](structures/partial-rectangle.md)
* `animate` Boolean (optional) _macOS_ or the better (IMO) way to do it would be to introduce a new All this is a bit interesting because I'm currently rewriting our docs parsing logic to be lossless ( |
As a side note (untested) our current typescript generator is literally just based on strings, you might just be able to do this and it would work. #### `win.setBounds(bounds[, animate])`
* `bounds` [Partial<Rectangle>](structures/rectangle.md)
* `animate` Boolean (optional) _macOS_ |
@BinaryMuse ok that clarifies this issue. I'm on 1.8.8 so all good. @MarshallOfSound I think the Tag approach sounds promising just needs some grammar rules for multiple cases like partial and optional. |
@MarshallOfSound ok I've tried out your last comments approach, which fails with: index.d.ts(1759,23): error TS2314: Generic type 'Partial' requires 1 type argument(s). and creates this as a resulting d.ts /**
* Resizes and moves the window to the supplied bounds. Any properties that are not
* supplied will default to their current values.
*/
setBounds(bounds: Partial, animate?: boolean): void; Note the lack of the generic type argument. Looking at the resulting {
"name": "setBounds",
"signature": "(bounds[, animate])",
"description": "Resizes and moves the window to the supplied bounds. Any properties that are not supplied will default to their current values.",
"parameters": [
{
"name": "bounds",
"type": "Partial",
"collection": false,
"innerType": "Rectangle",
"required": true
},
{
"name": "animate",
"type": "Boolean",
"collection": false,
"required": false
}
]
}, so it does map the type to Partial but properly puts So if I'm not mistaken, electron-typescript-defintions doesn't handle the case of Adding this quickfix inside the conditional checks solves the issue: } else if (originalType.type === "Partial" && type.innerType) {
newType = `Partial<${type.innerType}>`
} and I receive a proper d.ts /**
* Resizes and moves the window to the supplied bounds. Any properties that are not
* supplied will default to their current values.
*/
setBounds(bounds: Partial<Rectangle>, animate?: boolean): void; Now as said this is just a hacky quickfix but something along these lines should do the trick for your recommended approach for now until there is better support via Tags or custom PartialTypes. |
@BinaryMuse the issue is being labeled with documentation label but it doesn't seem to be documentation problem. Documentation is correct but typescript declaration is wrong. |
@vladimiry The TS defs are generated from our docs, if the defs are wrong it's a documentation issue. |
Got it. It's just a little misleading seeing just "documentation" label here while the solution requires fixing the code (presumably scripts that generate the ts-defs from the docs). PS would love to see |
Ouch thats quite long ago. My feature story at that time got abandoned so I didnt follow up on this any longer. @MarshallOfSound did you make any progress with your docs-gen rewrite? |
node_modules/.bin/electron --version
: v1.8.8Expected Behavior
When reading up the docs for BrowserWindow.setBounds I expected the function to take a
Partial<Rectangle>
as first argumentActual behavior
but instead the generated type definitions are:
Now what I'd be really looking for is some minor instruction on how to contribute such fixes by myself. Looking through the package.json of electron I noticed the use of a custom dependency to generate the definitions out of a previously generated api.json from this module. Now the later kinda sounds like the fix needs to be done inside the documentation. So after digging around the docs for the BrowserWindow show this content to define the method:
Am I on the right track with my assumptions? If so how would I mark the Rectangle of the bounds property to be Partial. Are there any docs to see all the available constructs to be used as annotation or which features of TS are supported (think of Unions, Conditional Types etc.)
The text was updated successfully, but these errors were encountered: