Typescript
Here are my typescript notes:
Typescript
The heart of typescript is in the typing objects. By doing so, you can prevent failures at build time because typescript will warn you if a type doesn’t match the result.
Do you want yo learn the basics? I can recommend this live with Matt Pocock
What is Zod
It is a superset of of typescript that enable you to specify types of typescript with a schema and some additional configurations.Learn it here with WebDevSimplified
What is tRPC
It is a form to send and recieve types through an API. Here is explained by WebDevSimplified
I prefer normal functions over arrow functions most of the time
This video explains it clearly.
Functions and objects
The difference between this
function LikeButton(param1, param2) {}
and this (note the ({})
)
function LikeButton({ param1, param2 }) {}
is that the parameters are an object inside the declaration of the function. This way you can group parameters and add personalized types (as interfaces). Like this:
interface IProps {
handleLike: () => void;
handleDislike: () => void;
}
function LikeButton({ handleLike, handleDislike }: IProps) {}
Adding auto-completion to config files
If you ever read this:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
That is a special comment saying: “this below should abide by the preset-classic
types.
You should npm install --save-dev @docusaurus/preset-classic
to have the nice auto-completion 😉.
Do I use Interfaces or Types?
It doesn’t matter for the most part. For the record, I use interfaces.
If you want the details, check the source: Harry Wolff - Interfaces vs Types
Sort your imports with prettier-plugin-sorted
I really like isort
for python, so I found an equivalent with prettier-plugin-sorted
what the heck is Pick
, Omit
, Exclude
, Extract
and Awaited
? (and more)
These are “pick-able” types. See this video.
Common errors
Node-gyp
error
solved in StackOverflow
this post comes from github, view it here