Flands

Typescript 有没有能对接 AI 的知识库或者文档?能处理稍微复杂点的类型

  •  
  •   Flands · Jul 15, 2025 · 2766 views
    This topic created in 325 days ago, the information mentioned may be changed or developed.

    最近写稍微复杂点的组件,发现 TS 的知识储备不够用,很多复杂的类型不好定义,花费了太多时间在 ts 上。 比如

    export type Field =
      | IFieldText
      | IFieldSingleSelect
    
    type IFieldText = {
      type: 'text'
    }
    
    type IFieldSingleSelect = {
      type: 'single_select'
    
      // 选项
      options: ISelectOption[]
    }
    
    

    此时我想定义一个表单,表单的 key 为 Field 联合类型中可能存在的 key ,此时会报 options 不存在

    type form:Field = { type: "", options: "" }
    

    还有表单的数据类型根据 field.type 进行变化等等 这种稍微复杂点的就抓耳挠腮,augment 写的也不好

    有没有更方便解决这种问题的办法

    4 replies    2025-07-16 08:38:45 +08:00
    weixind
        1
    weixind  
       Jul 15, 2025   ❤️ 1
    建议你先通过 AI 学习一下 TS 类型推断相关的内容,当你有一定思路的时候,再结合 AI ,该问题的答案就手到擒来。

    或者先玩下 type challenges

    "要用 AI 替代你的手,不要用 AI 替代你的脑子。” —— 莎士比亚
    andyskaura
        2
    andyskaura  
       Jul 15, 2025
    type form:Field 这是啥写法
    Dorathea
        3
    Dorathea  
       Jul 15, 2025
    Flands
        4
    Flands  
    OP
       Jul 16, 2025
    @andyskaura 打错了,const..
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2946 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 07:37 · PVG 15:37 · LAX 00:37 · JFK 03:37
    ♥ Do have faith in what you're doing.