Skip to content

jedrzejginter/ts-resolve-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-resolve-type

Requirements

  • Node 16 or higher
  • TypeScript 5 or higher
    • strict: true in tsconfig.json

Known limitations

  • 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

Installation

npm i -D ts-resolve-type typescript

Usage

// src/index.ts
type Keys = 1 | 2 | 3;

export type InputType = {
  [K in Keys]: number;
};

CLI

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;
};

Node.js

import { resolve } from "ts-resolve-type";

const resolved = await resolve("./src/index.ts", "InputType");

/*
const resolved = `type InputType = {
  1: number;
  2: number;
  3: number;
};`
*/

About

🖌️ Get fully resolved TypeScript type as code

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published