-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Add default values to TypeScript declaration files #19919
Comments
It doesn't seem this is possible unless I've done something wrong. Adding a default value onto a class member gives the following error when running
And adding one into a function signature errors with:
|
Yeah, I don't think TS typings (as opposed to source code) allow this. |
I see. As an alternative, would you consider adding the default value as a JSDoc comment: /**
* @param {string} [somebody=John Doe] - Somebody's name.
*/ Or any consistent way to parse the default values across the codebase? |
It was decided in #19940 not to do this. |
Including the information in the .js file was decided against yes, but what about having the default value in the declaration files since they are manually handled? Type information is already present in the declaration so it could be simply a Using my previous example: export class WebGLRenderer implements Renderer {
// ...
/**
* If autoClear is true, defines whether the renderer should clear the color buffer.
* @default true
*/
autoClearColor: boolean;
// ...
} |
Well, this seems reasonable to me 👍 . |
We just need someone to offer maintaining them. @dmnsgn is that something you would like to do? |
Just to confirm here — do VSCode and other editors display JSDoc on type defs, as a fallback to JSDoc on the source itself? I'm guessing that's true because the TS compiler copies JSDoc from source TypeScript to the type definitions when it compiles TS->JS, but I'm not really sure about how editors decide what to use. |
I might be able to update the initial comment definitions and PR, then I assume if defaults are changed for some reason in the js source files, the ts declaration files should be checked in parallel with the PR or when merging. @donmccurdy just tried in VSCode and it does: if I update /**
* If autoClear is true, defines whether the renderer should clear the color buffer. Default is true.
* @default true
*/
autoClearColor: boolean; it will appear: |
Sorry, if there is no maintainer taking care of this it will then have to be me. And I'm unable to maintain more things. |
- Now partially in Typescript - Dependencies updated - Split between model, view, and controller - WIP: controller not implemented yet
Description of the problem
Having definitions helps a lot but they are lacking the proper setting of the default value. It is usually in the comment just above each property so is there any blocker to include them as well.
See for instance:
three.js/src/renderers/WebGLRenderer.d.ts
Lines 128 to 141 in 4a8c4ae
could be:
It shouldn't be an issue since types are actually
export
ing classes and not justdeclare
ing them and could help parsing the codebase and monitor default allocations.Three.js version
N/A
Browser
N/A
OS
N/A
Hardware Requirements (graphics card, VR Device, ...)
N/A
The text was updated successfully, but these errors were encountered: