- Node 16 or higher
- TypeScript 5 or higher
strict: true
intsconfig.json
- The type has to be
export
'ed- Most probably it's because TypeScript checker ignores types that are not used (??)
- Does not resolve
enum
- Does not preserve function argument names
- Prints
args_0
,args_1
etc instead of original function arguments names
- Prints
npm i -D ts-resolve-type typescript
// src/index.ts
type Keys = 1 | 2 | 3;
export type InputType = {
[K in Keys]: number;
};
Find InputType
in src/index.ts
file and get the output type:
npx ts-resolve-type src/index.ts InputType
Outputs
type InputType = {
1: number;
2: number;
3: number;
};
import { resolve } from "ts-resolve-type";
const resolved = await resolve("./src/index.ts", "InputType");
/*
const resolved = `type InputType = {
1: number;
2: number;
3: number;
};`
*/