【问题标题】:Generated Figma plugin does not include TS typings生成的 Figma 插件不包含 TS 类型
【发布时间】:2021-10-24 01:49:49
【问题描述】:

我正在尝试按照 here 找到的插件设置指南进行操作,并且我有一个非常非常简单的插件,如下所示:

figma.showUI(__html__);

// @ts-ignore
console.log(figma.currentPage.selection[0].cornerRadius);

正如所写,插件工作正常并返回所选节点的边框半径。

但是,如果我删除 // @ts-ignore TS 会抱怨:“'SceneNode' 类型上不存在属性 'cornerRadius'。”

我已经安装了来自 here 的类型,我的 .tsconfig 看起来像这样:

{
  "compilerOptions": {
  "target": "es6",
  "lib": ["es6", "dom"],
  "typeRoots": [
    "./node_modules/@types",
    "./node_modules/@figma"
  ]
}

}

我错过了什么?

【问题讨论】:

    标签: typescript figma figma-api


    【解决方案1】:

    figma.currentPage.selectionreturns a SceneNode arraySceneNode 没有定义 cornerRadiusCornerMixin。您需要检查是否支持节点类型。

    即查看SceneNode 上的type 字段:

    const selection = figma.currentPage.selection[0];
    if (selection.type === "RECTANGLE") {
      console.log((selection as RectangleNode).cornerRadius);
    }
    
    

    以下类型使用CornerMixin,基于​​类型插件声明文件:

    RectangleNode
    EllipseNode
    PolygonNode
    StarNode
    VectorNode
    BooleanOperationNode
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 2023-02-04
      • 2023-03-12
      • 2021-11-26
      相关资源
      最近更新 更多