Skip to content

Array + Union 配置聯動 後 點擊添加項目報錯 #56

@eric2788

Description

@eric2788

配置範例如下 (使用官方參考的配置聯動2 + Array 形式)

import { Context, Schema } from 'koishi'

export const name = 'test'


export interface ConfigRef {
  shared: string
  type: 'foo' | 'bar' | 'baz'
  value?: number
  text?: string
}

export interface Config {
  configs: ConfigRef[]
}

export const Config: Schema<Config> = Schema.object({
  configs: Schema.array(Schema.intersect([
    Schema.object({
      shared: Schema.string(),
      type: Schema.union(['foo', 'bar', 'baz']).required(),
    }).description('基础配置'),
    Schema.union([
      Schema.object({
        type: Schema.const('foo').required(),
        value: Schema.number().default(114514),
      }).description('特殊配置 1'),
      Schema.object({
        type: Schema.const('bar').required(),
        text: Schema.string(),
      }).description('特殊配置 2'),
      Schema.object({} as any)
    ])
  ]))
})

export function apply(ctx: Context) {
  // write your plugin here
}

使用後,按下 添加項目 沒有反應且在 F12 console 出現如下報錯:

image

此問題只在 dev 出現,build好後從koishi市場下載插件,則沒有這個問題

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