While using Vite, the vite paths configuration can support the typescript aliases with the plugin vite-tsconfig-paths
export type Result<T, E> = { ok: true, result?: T } | { ok: false, err: E }
Advantages: everything.
Disadvantages: it creates an object for it.
It is a quick way to test it before using a small library https://shaarli.lyokolux.space/?NJ9Efg
aria-label
and aria-labelledby
are exclusive. So they can be enforced for components in typescript:
type ToggleSwitchProps = {
name: string;
checked: boolean;
handleToggle: () => void;
size?: "sm" | "lg" | "base";
classNames?: string;
} & ({ ariaLabel: string; ariaLabelledBy: never } | { ariaLabel: never; ariaLabelledBy: string });
How typescript types can improve safety?
It is interesting as it avoids a typescript to javascript compilation.
It works with plain JS too.
How to parse a programming language with typescript: here a small but working example
A tuple: type PersonProps = [string, number]
A variadic tuple: type Foo<T extends unknown[]> = [string, ...T, number];
A variadic tuple with 2 types:
type Bar<
T extends unknown[],
U extends unknown[]
> = [...T, string, ...U];
When you use satisfies, the value BEATS the type.
The value of the variables is taken into account instead of the type declared in semicolon.
Also colon annotations and satisfies are equally safe.
Also unlike satisfies and colon annotations, using ‘as’ annotations lets you lie to TypeScript.
To recap, we’ve got FOUR ways of assigning a type to a variable:
- colon annotations
satisfies
as
annotations- not annotating and letting TS infer it
The rule of thumb is that you should only use satisfies in two specific situations:
- You want the EXACT type of the variable, not the WIDER type.
- The type is complex enough that you want to make sure you didn’t mess it up
The project does not seem to be maintained anymore though :/
A great project to get started with hexagons (for example, a map).
js/ts utils
A project to use a Result type. This particular type contains a result or an error.
Would be my first pick to use in a JS environment