🛡️Atomico with Typescript
Atomico with Typescript will improve the scalability of your project thanks to a really productive type system when creating, distributing and maintaining webcomponents
With Atomico and Typescript you will be able to:
📌 If you are a Typescript user I recommend using TSX vs the template-string, as you will benefit from:
JSX runtime, Typescript will automatically import Atomico upon detecting the use of TSX.
Autocompletion and validation of attributes, properties and events of tags and webcomponents.
Webcomponent instance validation using constructors.
Construct the props parameter of your functional component.
Your component as a function does not infer the props, to help infer the props you should use the Props type, example:
From an object: Construct props directly from the declaring object.
From the component: Build the props from the component, internally Atomico captures the property component.props
.
From another customElement component: It's unusal, but when you extend another component you can infer the props from its constructor.
Check the correct declaration of your component.
Typescript checks the structure of your component by using the c
function on it, thus validating which props and styles have been attached.
The return of c
is a CustomElement with the types of the associated props, example:
It will report an error to Typescript since this component's props define that value is of type number
, this validation also applies when instantiating your CustromElement in JSX or TSX.
Both TSX or JSX will help you to build better applications since it verifies the types according to the definition of its component, this verification is Free, it does not need plugins, only a tsconfig.json
file and Typescript
to automate the revision.
Last updated