MasatoDev / boostest

14 stars 0 forks source link

Support Table #29

Closed MasatoDev closed 1 month ago

MasatoDev commented 1 month ago

Support Settings

Supports tsconfig file, so alias, etc. can be used.

Support Types

Types

type support example default result val
string string "test string data"
number number 10
bigint 100n 9007199254740991
boolean boolean true
undefined undefined undefined
null null null
any any "any"
unknown unknown undefined
never never null
object object {}
void void null
function ()=>void ()=>{}
array string[] []
union string \| number "test string data" (first val)
conditional string extends number ? true : false; true (true val)
symbol symbol Symbol()
tuple type [string, number] ["test string data", 10]
named tuple type [name: string, age: number] ["test string data", 10]
intersection type Hoge & {age: number} {...hoge(), ...{age: 10}}
reference type {name: [reference type name]} {name: [ReferenceTypeName]}
keyof × keyof T {}
typeof × typeof T {}
infer × infer T {}
mapped type × {[K in keyof T]: T[K]} {}
namespace × Namespace.Hoge {}
constructor type × abstract new (...args: any) => any {}
index accessor × Hoge['name'] {}
template × ${string} | {}

Utilities type

type support example default result val
ThisType<T> × ThisType<T> {}
Array<T> × Array<T> []
Partial<T> × Partial<T> {}
Required<T> × Required<T> {}
Readonly<T> × Readonly<T> {}
Pick<T, K> × Pick<T, K> {}
Omit<T, K> × Omit<T, K> {}
Extract<T, U> × Extract<T, U> {}
Exclude<T, U> × Exclude<T, U> {}
NonNullable<T> × NonNullable<T> {}
Parameters<T> × Parameters<T> {}
ConstructorParameters<T> × ConstructorParameters<T> {}
ReturnType<T> × ReturnType<T> {}
InstanceType<T> × InstanceType<T> {}
Promise<T> × Promise<T> {}

Support Targets

Type Aliases 👌

type User = {
  name: string,
  age: number
}

type Job = string

const _ = boostestUser<User>();
const _ = boostestJob<Job>();

/** The following function is generated in another file */
export function boostestUser<T>(args?: Partial<T>): T {
    return ({
        'name':'test string data',
        'age':10,
        ...args
    } as T);
}
export function boostestJob<T>() {
    return 'test string data';
}

Interface 👌

interface User {
  name: string,
  age: number
}

const result = boostestUser<User>();

/** The following function is generated in another file */
export function boostestUser<T>(args?: Partial<T>): T {
    return ({
        'name':'test string data',
        'age':10,
        ...args
    } as T);
}

Class (with constructor) 👌

Test data can be created using constructor

class User {
  name: string;
  age: number

  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }
}

const _ = boostestUser<typeof User>(User);

/** The following function is generated in another file */
export function boostestUser<T extends abstract new (...args: any) => any>(User): T {
    return new User('test string data', 10);
}

Support Import/Export

ESM

kind support example
default import import Hoge from '@/hoge';
import import { Hoge } from '@/hoge';
default export export default Hoge;
named export export type { Hoge as AnotherName }
named default export export type { Hoge as default }
export decl export interface Hoge { name: string; }
default export decl export default interface Hoge { name: string; }
export with import export type { Hoge } from './index';
named export with import export type { Hoge as AnotherName } from './index';

CommonJS

kind support example
export assignment × export = Hoge;
require × const hoge = require('./hoge.js');

Namespace 🙅‍♂️

not supported

declare namespace h {
  interface Hoge {name: string}
}

export = h;
import type { Hoge } from 'file';

let _ = boostestHoge<Hoge>();

/** Function is not generated */