Repository navigation
Documentation: Update coding guidelines to recommend TypeScript #81763
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
Changes from all commits
cffe47b
425a55c
c1d1dde
e69b841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -314,7 +314,6 @@ If you are publishing new versions of packages, note that there are versioning r | |
| ## TypeScript | ||
|
|
||
| The [TypeScript](https://www.typescriptlang.org/) language is a typed superset of JavaScript that compiles to plain JavaScript. | ||
| Gutenberg does not use the TypeScript language, however TypeScript has powerful tooling that can be applied to JavaScript projects. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗑️ |
||
|
|
||
| Gutenberg uses TypeScript for several reasons, including: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -346,7 +346,7 @@ function HookExample() { | |
|
|
||
| ## TypeScript | ||
|
|
||
| We strongly encourage using TypeScript for all new components. | ||
| All new components should be written in TypeScript. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to update the folder structure in this file, since it mentions creating
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I updated |
||
|
|
||
| Extend existing components’ props if possible, especially when a component internally forwards its props to another component in the package: | ||
|
|
||
|
|
@@ -680,9 +680,9 @@ As a result of the above guidelines, all new components (except for shared utili | |
| ```text | ||
| component-name/ | ||
| ├── stories | ||
| │ └── index.js | ||
| │ └── index.ts | ||
| ├── test | ||
| │ └── index.js | ||
| │ └── index.ts | ||
| ├── component.tsx | ||
| ├── context.ts | ||
| ├── hook.ts | ||
|
|
@@ -709,9 +709,9 @@ component-family-name/ | |
| │ ├── README.md | ||
| │ └── style.module.scss | ||
| ├── stories | ||
| │ └── index.js | ||
| │ └── index.ts | ||
| ├── test | ||
| │ └── index.js | ||
| │ └── index.ts | ||
| ├── context.ts | ||
| ├── index.ts | ||
| ├── types.ts | ||
|
|
@@ -753,19 +753,18 @@ If possible, the legacy version of the component should be rewritten so that it | |
| function LegacyComponent( props ) { | ||
| const newProps = useTranslateLegacyPropsToNewProps( props ); | ||
|
|
||
| return ( <NewComponentImplementation { ...newProps } /> ); | ||
| return <NewComponentImplementation { ...newProps } />; | ||
| } | ||
|
|
||
| // new-component/index.tsx | ||
| function NewComponent( props ) { | ||
| return ( <NewComponentImplementation { ...props } /> ); | ||
| return <NewComponentImplementation { ...props } />; | ||
| } | ||
|
|
||
| // new-component/implementation.tsx | ||
| function NewComponentImplementation( props ) { | ||
| // implementation | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| In case that is not possible (eg. too difficult to reconciliate new and legacy implementations, or impossible to preserve backward compatibility), then the legacy implementation can stay as-is. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered updating this title to something like "JavaScript (TypeScript)", "JavaScript / TypeScript", or just "TypeScript", but I also don't want to break any existing links to this section of the documentation. GitHub allows renaming an anchor via
<a name>so we could preserve existing anchor, but I'm not sure this would work in how the documentation is mirrored into the developer site.And frankly, I don't think it's wrong to continue titling the section "JavaScript", as ultimately JavaScript continues to be the basis of the language we write (TypeScript being a superset). And who knows, maybe some day this will be JavaScript syntax 🤷