egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.46k stars 209 forks source link

Type errors occur when used with browserslist-to-esbuild. #1111

Open odanado opened 2 months ago

odanado commented 2 months ago

Defining the following tsup.config.ts will result in a type error.

import { defineConfig } from "tsup";
import browserslistToEsbuild from "browserslist-to-esbuild";

defineConfig({
    target: browserslistToEsbuild(),
})

error:

Type 'string[]' is not assignable to type 'Target | Target[] | undefined'.
  Type 'string[]' is not assignable to type 'Target[]'.
    Type 'string' is not assignable to type 'Target'.(2322)

ref: https://www.typescriptlang.org/play/?ssl=2&ssc=1&pln=3&pc=1#code/JYWwDg9gTgLgBAbzgEwKYDNgDtUGEJaYDmcAvnOlBCHAEQwDOArmLQNwBQokscARlQDuDVFAYAbYAxgAVCAFEGfJsHHIKVGrQERhoiVJgBaGBCOolKtew4c0mHPkLAiACgQc4XuDACGUIlQYAC5+IRExSWk5RWVVZFcASgAaDlJEjiA

This is due to tsup's use of the literal type Union. https://github.com/egoist/tsup/blob/00188a0dc848c48fac45de245d1e021f370a84a3/src/options.ts#L88

Could adding (string & {}) to the type solve this problem? https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939

Upvote & Fund

Fund with Polar