From 035bada3634788e7dc47fa5aac6be1d1297ec0ed Mon Sep 17 00:00:00 2001 From: Akira Sudoh Date: Thu, 28 Jan 2021 18:22:15 +0900 Subject: [PATCH] docs(web-components): add notes on TypeScript definition files Adds implementation notes for TypeScript definition files in `@carbon/ibmdotcom-web-components` so that new developers can quickly understand the difference from regular NPM packages. Refs #4988. --- packages/web-components/IMPLEMENTATION_NOTES.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/web-components/IMPLEMENTATION_NOTES.md b/packages/web-components/IMPLEMENTATION_NOTES.md index 5269b088129..7e59afd1402 100644 --- a/packages/web-components/IMPLEMENTATION_NOTES.md +++ b/packages/web-components/IMPLEMENTATION_NOTES.md @@ -15,7 +15,7 @@ - [Rendering target](#rendering-target) - [Composite components](#composite-components) - [Components rendering modal](#components-rendering-modal) -- [CTA components](#cta-components)<<<<<<< implnotes-video-player +- [CTA components](#cta-components) - [Video CTA](#video-cta) - [React integration](#react-integration) - [React wrapper generator](#react-wrapper-generator) @@ -25,6 +25,7 @@ - [Container components](#container-components) - [Triggering action dispatcher](#triggering-action-dispatcher) - [Masthead search](#masthead-search) +- [TypeScript type definition](#typescript-type-definition) @@ -252,3 +253,11 @@ The search box feature in masthead consists of two things: `` uses [`ThrottledInputMixin`](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.13.0/packages/web-components/src/globals/mixins/throttled-input.ts) to throttle `dds-masthead-search-input` event. `ThrottledInputMixin` calls `_handleThrottledInput()` method, throttled, as the event defined by `eventInput` static method is fired. `` [intersects the search query with the table of loaded search results](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.13.0/packages/web-components/src/components/masthead/masthead-search-container.ts#L64-L70) and [sets `currentSearchResults` property](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.13.0/packages/web-components/src/components/masthead/masthead-search-container.ts#L72), which is [rendered as ``](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.13.0/packages/web-components/src/components/masthead/masthead-search-composite.ts#L118-L123). + +## TypeScript type definition + +All TypeScript code in our source code is transpiled to plain JavaScript code, by a [Babel plugin](https://www.npmjs.com/package/@babel/plugin-transform-typescript). Applications can still refer to our TypeScript types, via `.d.ts` files we ship. + +The `.d.ts` files are generated by [regular TypeScript toolchain](https://www.npmjs.com/package/typescript), via [`gulp-typescript`](https://www.npmjs.com/package/gulp-typescript). The build procedure can be found at [here](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.15.0/packages/web-components/gulp-tasks/build.js#L474-L490). + +> 💡 The `.d.ts` for React wrappers are generated by our [custom Babel plugin](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.15.0/packages/web-components/tools/babel-plugin-create-react-custom-element-type-def.js). An example of such `.d.ts` file can be found [here](https://unpkg.com/@carbon/ibmdotcom-web-components@1.0.0/es/components-react/card/card.d.ts). The build procedure can be found [here](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/blob/v1.15.0/packages/web-components/gulp-tasks/build.js#L388-L397).