-
Notifications
You must be signed in to change notification settings - Fork 134
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
RFC: @defaultValue to indicate a default value #27
Comments
This tag seems to still be useful for properties and fields. It seems less applicable for function parameters with the introduction of default values accessible in the AST with ES6+ and TS. However, it's still applicable on the JS side of things IMHO due to call time evaluation and default parameters being available for later evaluation (examples taken from here):
or default parameters being available to later default parameters
Granted JS examples on tricky edge cases, but likely as well w/ TS? The The examples above would cause trouble for various documentation tooling pipelines likely as resolving things requires a two pass algorithm and potential evaluation which can be fragile where the |
Based on the discussion with office-ui-fabric-react, we're thinking
Usage example: enum WarningStyle {
DialogBox,
StatusMessage,
LogOnly
}
interface IWarningOptions {
/**
* Determines how the warning will be displayed.
*
* @remarks
* See {@link WarningStyle| the WarningStyle enum} for more details.
*
* @default `WarningStyle.DialogBox`
*/
warningStyle: WarningStyle;
/**
* Whether the warning can interrupt a user's current activity.
* @default
* The default is `true` unless
* `WarningStyle.StatusMessage` was requested.
*/
cancellable?: boolean;
/**
* The warning message
*/
message: string;
} |
I noticed that although JSDoc supports Document the number value of a constant /**
* @constant
* @default
*/
const RED = 0xff0000; I interpret this to mean that, JSDoc parses I'm also not even sure this is needed with TypeScript. In my experience the type system already makes it fairly easy to determine whether or not a variable is a constant whose value should be documented. Since JSDoc defines
This ensures that the two scenarios don't get confused, and we won't need a special grammar rule to handle this tag. |
Updated usage example: enum WarningStyle {
DialogBox,
StatusMessage,
LogOnly
}
interface IWarningOptions {
/**
* Determines how the warning will be displayed.
*
* @remarks
* See {@link WarningStyle| the WarningStyle enum} for more details.
*
* @defaultValue `WarningStyle.DialogBox`
*/
warningStyle: WarningStyle;
/**
* Whether the warning can interrupt a user's current activity.
* @defaultValue
* The default is `true` unless
* `WarningStyle.StatusMessage` was requested.
*/
cancellable?: boolean;
/**
* The warning message
*/
message: string;
} |
Related TypeStrong/typedoc#856 Typedoc show values but in some cases that isn't desired, such as here when the text is super long. |
@octogonz How about documenting default function parameters? What will that look like? |
@sindresorhus After thinking about this question, I don't think |
Hi @octogonz , sorry don't know where to ask, hope this would be a good place. You've outlined that Let me provide you an example:
This is quite common approach for declaring React component props, and as you see function has no default parameters, at least in obvious way, so my question is, should it be ok to use |
Short answer: Yes Long answer: My perspective comes from projects where we are designing third-party APIs with an API documentation website. So I would try to write it something like this: interface IButtonCoreProps {
/**
* This is identify Button type
* @defaultValue? ButtonType.DEFAULT
*/
type?: ButtonType;
children: React.ReactNode;
};
type ButtonProps = IButtonCoreProps & Omit<JSX.IntrinsicElements['button'], 'children'>; The reason is that an Whereas But these concerns maybe aren't relevant to your case. The Maybe the TSDoc spec should say it in a more general way, like: More thoughts about stereotypesI'm reluctant for TSDoc to specify stereotypes. They seem like an implementation detail that may vary between documentation tools. For example, one tool might consider this to be a "function": /**
* @param x - the input
* @returns the result
*/
const f: (x: string) => string; Another tool may consider it to be a "variable" whose value is a mishmash of algebra. What about this thing below? /**
* Some docs
*/
const f:
/**
* @param x - the input
* @returns the result
*/
((x: string) => string) |
/**
* @param x - the input
* @returns the result
*/
((x: number) => number); Is that two "functions" in there? API Extractor would consider it a misuse of TSDoc. But if some other tool has a way to present Perhaps what we should specify is a minimal set of "core" stereotypes that all TSDoc implementors should be expected to recognize. If you write doc comments using those patterns, you know they will have consistent behavior everywhere. |
In API Extractor issue #720 @RueDeRennes asked about supporting
@default
to indicate a default value.Some questions:
@default
or@defaultValue
?The text was updated successfully, but these errors were encountered: