Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
This repository was archived by the owner on Dec 7, 2024. It is now read-only.

New Method! #12

@SimonMeskens

Description

@SimonMeskens

@tycho01 @nadameu @masaeedu

TypeProps will probably be coming back, HKTs just became trivial:

// Functor
interface StaticFunctor<P extends TypeProp> {
    map<T, U>(transform: (a: T) => U, mappable: Of<P, [T]>): Of<P, [U]>;
}

// Prop
interface ArrayProp extends TypeProp {
    params: this["args"][0] extends Array<infer T> ? [T] : never;
    type: this["args"][0][];
}

// Examples
const arrayFunctor: StaticFunctor<ArrayProp> = {
    map: <A, B>(fn: (a: A) => B, fa: A[]): B[] => {
        return fa.map(fn);
    }
};

// TypeProps Library

interface TypeProp {
    args: any[];
    params: unknown[];
    type: unknown;
}

type From<Prop extends TypeProp, T = Of<Prop>> = (Prop & { args: [T] })["params"];
type Of<Prop extends TypeProp, T extends unknown[] = unknown[]> = (Prop & {
    args: T;
})["type"];

Big thanks to @strax for the new insight. Unfortunately there's a bug in TS 3.4.4 that stops us from using it right now in typescript@latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions