You are on page 1of 1

Filter a record type by key in TS using mapped types:

[K in keyof T as Condition<K> extends true ? K : never]: T[P] // use type casting

type Chainable<T = {}> = {


option<K extends PropertyKey, V>(key:K extends keyof T ? never : K, value: V):
Chainable<Record<K, V> & Omit<T, K>>;
get(): T
}

type Mutable<T extends object> = {


-readonly [P in keyof T]: T[P];
};

store.$onAction has state as a second argument

Most of the time, getters will only rely on the state, however, they might need to
use other getters. Because of this, we can get access to the whole store instance
through this when defining a regular function but it is necessary to define the
type of the return type (in TypeScript). This is due to a known limitation in
TypeScript and doesn't affect getters defined with an arrow function nor getters
not using this

<aside> html element

One can use Teleport to conditionally render an element at two places.


<Teleport to="#el" :disabled="screens.lg">
<!-- element -->
</Teleport>

Element id, parent in cAPI:


const instance = getCurrentInstance();
console.log(instance.parent)

Good software practices


- always choose the simplest way of doing things - ex. map with implicit return vs
explicit return
- there should be only one way of doing things - ex. multiple ways of calling a
function confuses people
- Our goal is to help users achieve their goals, so if there is a (potential) known
issue, there should be an explicit error message for it so we get feedback from
them. If it is a generic error we won't know how to help/improve the software.
- Always write down newly introduced tech debt

You might also like