This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Concrete<T> = new (...params: any[]) => T; | |
type Abstract<T> = abstract new (...params: any[]) => T; | |
type Factory<T> = (...params: any[]) => T; | |
type AsyncFactory<T> = (...params: any[]) => Promise<T>; | |
type Ref<T> = Concrete<T> | Abstract<T>; | |
type Use<T> = Concrete<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Abstract<T, P extends unknown[] = never[]> = abstract new ( | |
...args: P | |
) => T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Abstract, AsyncFactory, Constructor, Factory, Params } from './types'; | |
import { validate } from './validate'; | |
import { Token } from './token'; | |
type Ref<T> = Token<T> | Abstract<T> | Constructor<T>; | |
type Use<T> = Constructor<T> | Factory<T> | AsyncFactory<T> | T; | |
interface Config<T> { | |
ref: Ref<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createWriteStream, PathLike } from "node:fs"; | |
import { Console } from "node:console"; | |
export const logger = <T>(path: PathLike, data: T[]) => { | |
const stream = createWriteStream(path); | |
const console = new Console(stream); | |
console.table(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Abstract<T = any> = abstract new (...params: any[]) => T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Abstract} from './abstract' | |
import {Type} from './type' | |
export type AbstractConstructorParams<T extends Type> = | |
ConstructorParameters<T> extends { | |
length: 1 | |
} | |
? [Abstract<ConstructorParameters<T>[0]>] | |
: ConstructorParameters<T> extends {length: 2} | |
? [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Callback} from './callback' | |
export class Action<T> { | |
constructor(public type: string, public value: T) {} | |
} | |
export const createAction = <T>(type: string) => { | |
return class extends Action<T> { | |
constructor(value: T) { | |
super(type, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Callback<T> { | |
(value: T): void; | |
} | |
function merge<T>(form: HTMLFormElement) { | |
const watchers = new Set<Callback<T>>(); | |
const fields = Array.from(form.elements) as HTMLInputElement[]; | |
const value = <T>(form: HTMLFormElement) => { | |
const data = new FormData(form); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Tag = `${string}-${string}`; | |
type TagMap = HTMLElementTagNameMap; | |
interface CustomElement<T> extends CustomElementConstructor { | |
new (...params: any[]): T; | |
} | |
function define<S extends Tag, K extends keyof TagMap>(selector: S, is?: K) { | |
return (target: CustomElement<TagMap[K]>) => { |
NewerOlder