phryneas / remark-typescript-tools

MIT License
129 stars 7 forks source link

Try to instrumentalize tsserver to extract evaluated types #5

Open phryneas opened 3 years ago

phryneas commented 3 years ago

So, essentially we need a new plugin that parses codeblocks like this:

```ts documentation
import { createSlice } from "@reduxjs/toolkit";
import { A } from "ts-toolbelt";

type Id<T> = { [K in keyof T]: T[K] } & {};

declare function withParams<T extends (...args: any[]) => unknown>(fn: T, cb?: (params: Parameters<T>) => void): void;
declare function getParams<T extends (...args: any[]) => unknown>(fn: T): Parameters<T>;
declare function compute<T>(t: T): A.Compute<T, "deep">;
declare function id<T>(t: T): Id<T>;
declare function quickinfo(target: any): void;

withParams(createSlice, ([sliceOptions]) => quickinfo(sliceOptions));

const sliceOptions = id(getParams(createSlice)[0]);
quickinfo(sliceOptions.extraReducers);

and displays everything wrapped in `quickinfo` as nice markdown instead of that codeblock
phryneas commented 3 years ago

Did some experiments, can be seen in https://gist.github.com/phryneas/5ff0ed00fca812d3f4f1d18651712706#file-output-log

Basically that (and existing plugins in this repo) are all the building parts - challenges would now be to