You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
Typescript can help detect errors earlier in the workflow and results in easier to understand code.
E.g. Let's look at Props for example
Javascript: No requirement to declare the type of Props. Any property can be passed. Invalid prop usage is not detected until runtime.
const JSComponent = (props) => {
return (
{props.x}
{props.y}
{props.anotherInvalidProp}
);
}
Typescript: Exact props type must be specified. Errors are highlighted at compile time and it’s much easier to identify the component interface.
interface Props {
x: number,
y: number
}
Typescript can help detect errors earlier in the workflow and results in easier to understand code.
E.g. Let's look at Props for example
Javascript: No requirement to declare the type of Props. Any property can be passed. Invalid prop usage is not detected until runtime.
const JSComponent = (props) => {
return (
Typescript: Exact props type must be specified. Errors are highlighted at compile time and it’s much easier to identify the component interface.
interface Props {
x: number,
y: number
}
const TSComponent = (props: Props) => {
return (
{props.x}
{props.y}
{props.anotherInvalidProp}
);
}
Fortunately it’s possible to migrate at your own pace: https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
The text was updated successfully, but these errors were encountered: