Skip to content
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

Increase severity of JSDoc to error. #20427

Merged
merged 9 commits into from
Mar 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Draft new coding standard for Record.
  • Loading branch information
sainthkh committed Mar 19, 2020
commit e95f1d601de7affa0168eb952b67a56c86f5843a
8 changes: 5 additions & 3 deletions docs/contributors/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ If you use a [TypeScript integration](https://github.com/Microsoft/TypeScript/wi

For packages which do not distribute their own TypeScript types, you are welcomed to install and use the [DefinitelyTyped](http://definitelytyped.org/) community-maintained types definitions, if one exists.

### Record Types
### Generic Types

When documenting a generic type such as `Object`, `Function`, `Promise`, etc., always include details about the expected record types.

Expand All @@ -282,11 +282,13 @@ When documenting a generic type such as `Object`, `Function`, `Promise`, etc., a

// Correct:

/** @type {Object<string,number>} */
/** @type {Record<string,number>} */ /* or */ /** @type {{[setting:string]:any}} */
/** @type {(key:string)=>boolean} */
/** @type {Promise<string>} */
```

When the name of the key for an object provides hints for developers what to do, use indexable interface like `{[setting:string]:any}`. If not, use `Record`.

The function expression here uses TypeScript's syntax for function types, which can be useful in providing more detailed information about the names and types of the expected parameters. For more information, consult the [TypeScript `@type` tag function recommendations](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#type).

In more advanced cases, you may define your own custom types as a generic type using the [TypeScript `@template` tag](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#template).
Expand All @@ -312,7 +314,7 @@ Similar to the "Custom Types" advice concerning type unions and with literal val
/**
* Hash of breakpoint names with pixel width at which it becomes effective.
*
* @type {Object<WPBreakpoint,number>}
* @type {Record<WPBreakpoint,number>}
*/
const BREAKPOINTS = { huge: 1440 /* , ... */ };
```
Expand Down