-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: TypeScript support in Custom Applications and release
v21.8
(#…
…2624) * docs: document typescript use in custom applications * docs: linter improvements * docs: improvements * docs: update typescript setup docs * docs: improvements * docs: update and improve typescript docs * docs: typo * docs: add release note for v21.8 * docs: improvements based on suggestions * docs: improve wording * docs: wording improvements Co-authored-by: Stephen Armstrong <[email protected]> * docs: wording improvements * ci: trigger Co-authored-by: Nicola Molinari <[email protected]> Co-authored-by: Stephen Armstrong <[email protected]>
- Loading branch information
1 parent
9334db6
commit 363a624
Showing
10 changed files
with
197 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
title: Adding TypeScript | ||
--- | ||
|
||
[TypeScript](https://www.typescriptlang.org/) is a typed superset of JavaScript that compiles to plain JavaScript. | ||
|
||
Custom Applications have full support for developing applications in TypeScript. | ||
|
||
<Info> | ||
|
||
This feature is available from version `21.8.0` onwards. | ||
|
||
</Info> | ||
|
||
To start a new Custom Application project with TypeScript, you can use the TypeScript starter template: | ||
|
||
```console noPromptLines="2-3" | ||
npx @commercetools-frontend/create-mc-app@latest \ | ||
my-new-custom-application-project \ | ||
--template starter-typescript | ||
``` | ||
|
||
The TypeScript starter template is the same as the standard JavaScript starter template in terms of functionality but it also includes the additional TypeScript setup. | ||
|
||
# Configuration | ||
|
||
Every TypeScript project requires a `tsconfig.json` file to instruct TypeScript how to compile the project. | ||
|
||
Therefore, we provide a base TSConfig to be used in your `tsconfig.json` file: | ||
|
||
```json | ||
{ | ||
"extends": "@commercetools-frontend/application-config/tsconfig-mc-app.json" | ||
} | ||
``` | ||
|
||
Furthermore, we provide a `client.d.ts` declaration file with some basic type shims for importing media assets: | ||
|
||
- `.mod.css` and `.module.css` | ||
- `.png` | ||
- `.svg` | ||
|
||
You can include this using the TypeScript triple-slash directives: | ||
|
||
```ts | ||
/// <reference types="@commercetools-frontend/application-config/client" /> | ||
``` | ||
|
||
<Info> | ||
|
||
By default, this is included in the TypeScript starter template `src/index.tsx` entry point file. | ||
|
||
</Info> | ||
|
||
You can also include this in the `tsconfig.json` file in the `compilerOptions.types` field but we don't recommend | ||
doing so unless you are very familiar with the [implications of using the `types` field](https://www.typescriptlang.org/tsconfig#types). | ||
|
||
Additional adjustments to other config files are also required, in particular: | ||
|
||
- `.prettierrc`: use the `typescript` parser. | ||
- `jest.test.config.js`: use the `@commercetools-frontend/jest-preset-mc-app/typescript` preset. | ||
- `jest.eslint.config.js`: include the file extensions `ts` and `tsx` in `moduleFileExtensions`, then `<rootDir>/**/*.ts` and `<rootDir>/**/*.tsx` in `testMatch`. | ||
|
||
<Info> | ||
|
||
The TypeScript setup is already preconfigured when using the TypeScript starter template. Consider this document as a reference to match your setup. | ||
|
||
</Info> | ||
|
||
# Migrate to TypeScript | ||
|
||
If you have an existing Custom Application project and want to migrate to TypeScript, you should do the following: | ||
|
||
* Install the `typescript` dependency. | ||
* Add a `tsconfig.json` file. See [configuration](#configuration) for the tooling setup. | ||
* Migrate the JavaScript files to TypeScript, using either `.ts` or `.tsx` (if a file contains JSX syntax). | ||
|
||
<Info> | ||
|
||
Migrating source files to TypeScript can be done incrementally. We recommend starting from the "leaf files" and working up to the application entry point. | ||
The [migrating from JavaScript documentation](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html) can help you set up a basic plan. | ||
|
||
All UI Kit and ApplicationKit packages provide declaration files and export useful types when necessary. | ||
|
||
During migration you might need to loosen up the types strictness, for example by allowing explicit `any` types. | ||
|
||
```json title="tsconfig.json" | ||
{ | ||
"extends": "@commercetools-frontend/application-config/tsconfig-mc-app.json", | ||
"compilerOptions": { | ||
"noExplicitAny": false, | ||
"strict": false | ||
} | ||
} | ||
``` | ||
|
||
You should revert these once migration is complete, as using `any` should be avoided. | ||
|
||
</Info> | ||
|
||
* Add the script command `"typecheck": "tsc --noEmit"` to your `package.json` to run the type checks of the application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
date: 2022-07-04 | ||
title: Custom Applications v21.8 | ||
description: The Application Kit packages have been released with several new features. | ||
type: feature | ||
topics: | ||
- CLI | ||
- Configuration | ||
- Templates | ||
- UI Components | ||
--- | ||
|
||
The Application Kit packages have been released with a minor version `v21.8`. | ||
|
||
This release includes several new features that we would like to present: | ||
|
||
* Official support for developing Custom Applications in [TypeScript](https://www.typescriptlang.org/), including a new starter template. Read more about TypeScript in the [Adding TypeScript](/development/adding-typescript) page. | ||
* New policy option for configuring the `audience` field when [integrating your Custom Application with an external API](/concepts/integrate-with-your-own-api#configuring-the-audience-policy). | ||
* Improved accessibility of different elements using ARIA attributes. | ||
* Simpler and more readable list of time zone data, available from the `@commercetools-frontend/l10n` package. | ||
* New React hook `useProjectExtensionImageRegex` for accessing the project images configuration, available from the `@commercetools-frontend/application-shell-connectors` package. | ||
|
||
As always, if you have questions or feedback you can open a [GitHub Discussion](https://github.com/commercetools/merchant-center-application-kit/discussions) or a [GitHub Issue](https://github.com/commercetools/merchant-center-application-kit/issues). | ||
|
||
<!--more--> | ||
|
||
# Deprecations | ||
|
||
The `mc-scripts` CLI has deprecated some entry points. | ||
|
||
Importing the function `createPostcssConfig` from the main entry point `@commercetools-frontend/mc-scripts` is now deprecated. Use the entry point `@commercetools-frontend/mc-scripts/postcss` instead. | ||
|
||
```diff | ||
const { | ||
createPostcssConfig, | ||
-} = require('@commercetools-frontend/mc-scripts'); | ||
+} = require('@commercetools-frontend/mc-scripts/postcss'); | ||
``` | ||
|
||
Importing the functions `createWebpackConfigForDevelopment` and `createWebpackConfigForProduction` from the main entry point `@commercetools-frontend/mc-scripts` is now deprecated. Use the entry point `@commercetools-frontend/mc-scripts/webpack` instead. | ||
|
||
```diff | ||
const { | ||
createWebpackConfigForDevelopment, | ||
createWebpackConfigForProduction, | ||
-} = require('@commercetools-frontend/mc-scripts'); | ||
+} = require('@commercetools-frontend/mc-scripts/webpack'); | ||
``` |
363a624
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.
Deploy preview for merchant-center-application-kit ready!
✅ Preview
https://merchant-center-application-1mns5yq0y-commercetools.vercel.app
Built with commit 363a624.
This pull request is being automatically deployed with vercel-action