这是indexloc提供的服务,不要输入任何密码
Skip to content

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

@odanado

Description

@odanado

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.

export type Target = BrowserTarget | BrowserTargetWithVersion | EsTarget

Could adding (string & {}) to the type solve this problem?
microsoft/TypeScript#29729 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions