Git Product home page Git Product logo

Comments (1)

shigma avatar shigma commented on June 14, 2024 6

这个行为是预期的。

  1. 在一些情况下我们是需要用到「intersect 中多个对象存在相同属性」这一特性的,可以参考文档中关于配置联动的示例。
  2. 更一般的情况下,我们也无法直接判断两个相同属性之间的包含关系,不应该做贸然合并(尽管对于显而易见的冲突情况我们可以报错,但这就是另一个问题了,并且实际场景中也不会有人这么用)。

对于你的需求,可以这样实现:

interface SharedConfig {
  foo: string
}

const SharedConfig = Schema.object({
  foo: Schema.string(),
})

interface Config1 extends SharedConfig {
  bar: boolean
}

const Config1 = Schema.object({
  bar: Schema.boolean(),
}) // 不写 SharedConfig 相关属性,或者 hidden

interface Config2 extends SharedConfig {
  baz: number
}

const Config2 = Schema.object({
  baz: Schema.number(),
}) // 不写 SharedConfig 相关属性,或者 hidden

interface FinalConfig extends Config1, Config2 {}

const FinalConfig = Schema.intersect([
  SharedConfig,
  Config1,
  Config2,
])

from koishi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.