Skip to content

Instantly share code, notes, and snippets.

View anztrax's full-sized avatar
🎯
Focusing

andrew ananta gondo anztrax

🎯
Focusing
View GitHub Profile
@anztrax
anztrax / Awaited.ts
Created November 30, 2025 00:40
Simple implementation of Awaited in Typescript
type MyAwaited<T> = T extends PromiseLike<infer A> ? MyAwaited<A> : T;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type X = Promise<string>
type Y = Promise<{ field: number }>
type Z = Promise<Promise<string | number>>
type Z1 = Promise<Promise<Promise<string | boolean>>>
type T = { then: (onfulfilled: (arg: number) => any) => any }
@anztrax
anztrax / If.ts
Created November 30, 2025 00:46
simple implementation of If in Typescript
/* _____________ Your Code Here _____________ */
type If<C extends boolean, T, F> = C extends true ? T: F
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<If<true, 'a', 'b'>, 'a'>>,
Expect<Equal<If<false, 'a', 2>, 2>>,
@anztrax
anztrax / ReadonlyAndExclude.ts
Created December 1, 2025 02:47
Simple implementation of Readonly + Exclude in Typescript
type MyReadonly2<T, K extends keyof T = keyof T> = {
readonly [P in K] :T[P]
} & {
[P in keyof T as P extends K ? never : P] : T[P]
}
@anztrax
anztrax / Concat.ts
Created December 1, 2025 02:55
Simple implementation of concat 2 array in TS type
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U]
@anztrax
anztrax / Include.ts
Created December 1, 2025 03:06
Simple implementation of Includes in Typesscript
type Includes<T extends readonly any[], U> =
T extends [infer First, ...infer Rest]
? (
Equal<First, U> extends true
? true
: Includes<Rest, U>
)
: false
/* _____________ Test Cases _____________ */
@anztrax
anztrax / Push.ts
Created December 1, 2025 03:11
Simple implementation of Push 2 generics in TS
type Push<T extends unknown[], U> = [...T, U]
@anztrax
anztrax / Unshift.ts
Created December 1, 2025 03:17
Simple implementation of Unshift Array in Typescript
type Unshift<T extends unknown[], U> = [U, ...T]
@anztrax
anztrax / MyParameter.ts
Created December 1, 2025 03:32
Simple implementation of Parameter Utils in typescript
type MyParameters<T extends (...args: any[]) => any> = T extends (...any:infer S) => any ? S: any
@anztrax
anztrax / MyOmit.ts
Created December 1, 2025 03:43
Simple implementation of Omit in typescript
type MyOmit<T, K extends keyof T> = {
[P in keyof T as P extends K ? never: P] :T[P]
}
@anztrax
anztrax / DeepReadOnly.ts
Created December 1, 2025 03:55
Create Simple implementation of DeepReadOnly in typescript
type DeepReadonly<T> = {
readonly [K in keyof T]:
T[K] extends Function
? T[K]
: T[K] extends { [K in string] : any}
? DeepReadonly<T[K]>: T[K]
}