Skip to content

Instantly share code, notes, and snippets.

View Asqit's full-sized avatar

Ondřej Tuček Asqit

View GitHub Profile
{
"show_edit_predictions": false,
"collaboration_panel": {
"dock": "left"
},
"git_panel": {
"dock": "left"
},
"lsp": {
"vtsls": {
// -------------------------------------> 1. Reversing a list
namespace Reverse {
// How does it work?
// 1. check if it`s possible to destructure a param into a tuple where we select first element and spread the rest
// 2.1 if it`s possible, then recursively repeat the first step by putting the first item as a second part of the tuple
// 2.2 if it`s not possible, then return an empty array
type Reverse<A extends unknown[]> = A extends [infer Item, ...infer Rest] ? [...Reverse<Rest>, Item] : [];
type initString = ["doing", "you", "are", "how"];
type initNumber = [9, 7, 5, 3, 1];
@Asqit
Asqit / type-level-typescript.ts
Last active July 29, 2024 14:26
Type-leve-typescript
//====================================================
// Type-level Typescript
// build-in language in the compiler level
//====================================================
// 1. Functions -------------------------
const makeTuple = (a: number, b: string) => [a, b];
type MakeTuple<T extends number, U extends string> = [T, U];
// 2. Conditionals ----------------------