Skip to content

Instantly share code, notes, and snippets.

View Lucifier129's full-sized avatar
🎯
Focusing

工业聚 Lucifier129

🎯
Focusing
View GitHub Profile
type ProcedureContext = {
path: Procedure[];
next: (procedure: Procedure) => void;
};
type Procedure = {
run: (ctx: ProcedureContext) => unknown;
};
const runProcedure = (
@Lucifier129
Lucifier129 / recoil-via-build-system.ts
Created May 13, 2021 03:37
implement recoil-like api via build-system abstraction
export type Fetch<K = unknown, V = unknown> = (key: K) => V
type Task<K = unknown, V = unknown> = (fetch: Fetch<K, V>) => V
type Tasks<K = unknown, V = unknown> = (key: K) => Task<K, V> | null
type Store<K, V> = Map<K, V>
type Build<K, V> = (tasks: Tasks<K, V>, key: K, store: Store<K, V>) => void
type PassengerEnName = {
type: 'PassengerEnName';
firstname: string;
middlename?: string;
lastname: string;
};
type PassengerCnName = {
type: 'PassengerCnName';
firstname: string;
type ResourcesValue<T> = T extends []
? never
: T extends [Resource<infer V>]
? [V]
: T extends [Resource<infer V>, ...infer Rest]
? [V, ...ResourcesValue<Rest>]
: never;
type InitResource = {
init<T>(
const log = (message) => {
return {
__typename: 'log',
message,
};
};
const raise = (message) => {
return {
__typename: 'exception',
function pipe<T, A>(a: T[], a1: ListAction<T, A>): A[];
function pipe<T, A, B>(a: T[], a1: ListAction<T, A>, a2: ListAction<A, B>): B[];
function pipe<T, A, B, C>(
a: T[],
a1: ListAction<T, A>,
a2: ListAction<A, B>,
a3: ListAction<B, C>
): C[];
type ParseResult = {
success: boolean,
data: any,
source: string
}
type ParseFailed = {
suceess: false,
data: any,
source: string
type ToTS<T extends string> =
T extends 'Int'
? number
: T extends 'String'
? string
: T extends 'Bool'
? boolean
: never
type GraphQLObject<T extends string> =
T extends `\ntype ${infer TypeName} {\n${infer Fields}}\n`
? {
name: TypeName,
fields: {
[key in keyof GraphQLObjectFields<Fields>]: GraphQLObjectFields<Fields>[key]
}
}
: never
type NullElement = null | undefined;
type BasicElement = number | boolean | string;
type ArrayElement = Array<VElement>;
type ObjectElement = {
props: {
children?: ArrayElement;
};