From 20987e98f389647a4614d8848e8eb4b3b099e7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20=28Kevin=29?= Date: Mon, 31 Oct 2022 22:04:16 +0800 Subject: [PATCH] fix: internal TS type errors (#187) Co-authored-by: Anthony Fu --- src/rollup/index.ts | 10 +++++----- src/types.ts | 4 ++-- src/vite/index.ts | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rollup/index.ts b/src/rollup/index.ts index 4b6f2024..5d9b5f89 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -1,17 +1,17 @@ import type { RollupPlugin, UnpluginContextMeta, UnpluginFactory, UnpluginInstance, UnpluginOptions } from '../types' import { toArray } from '../utils' -export function getRollupPlugin ( - factory: UnpluginFactory, -): UnpluginInstance['rollup'] { - return (userOptions?: UserOptions) => { +export function getRollupPlugin ( + factory: UnpluginFactory, +) { + return ((userOptions?: UserOptions) => { const meta: UnpluginContextMeta = { framework: 'rollup', } const rawPlugins = toArray(factory(userOptions!, meta)) const plugins = rawPlugins.map(plugin => toRollupPlugin(plugin)) return plugins.length === 1 ? plugins[0] : plugins - } + }) as UnpluginInstance['rollup'] } export function toRollupPlugin(plugin: UnpluginOptions, containRollupOptions = true): RollupPlugin { diff --git a/src/types.ts b/src/types.ts index 2322bac8..3fcd1ee5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -69,7 +69,7 @@ export interface ResolvedUnpluginOptions extends UnpluginOptions { __virtualModulePrefix: string } -export type UnpluginFactory = (options: UserOptions, meta: UnpluginContextMeta) => +export type UnpluginFactory = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array : UnpluginOptions @@ -77,7 +77,7 @@ export type UnpluginFactoryOutput = undefined extends UserO ? (options?: UserOptions) => Return : (options: UserOptions) => Return -export interface UnpluginInstance { +export interface UnpluginInstance { rollup: UnpluginFactoryOutput : RollupPlugin> vite: UnpluginFactoryOutput : VitePlugin> webpack: UnpluginFactoryOutput diff --git a/src/vite/index.ts b/src/vite/index.ts index f9eec52f..2a1824ad 100644 --- a/src/vite/index.ts +++ b/src/vite/index.ts @@ -2,10 +2,10 @@ import { toRollupPlugin } from '../rollup' import type { UnpluginContextMeta, UnpluginFactory, UnpluginInstance, VitePlugin } from '../types' import { toArray } from '../utils' -export function getVitePlugin ( - factory: UnpluginFactory, -): UnpluginInstance['vite'] { - return (userOptions?: UserOptions) => { +export function getVitePlugin ( + factory: UnpluginFactory, +) { + return ((userOptions?: UserOptions) => { const meta: UnpluginContextMeta = { framework: 'vite', } @@ -20,5 +20,5 @@ export function getVitePlugin ( }) return plugins.length === 1 ? plugins[0] : plugins - } + }) as UnpluginInstance['vite'] }