0

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

figma.showUI(__html__);

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

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

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

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

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

}

我错过了什么?

4

1 回答 1

1

figma.currentPage.selection 返回一个SceneNode数组SceneNode没有CornerMixinwhich 定义cornerRadius。您需要检查是否支持节点类型。

即查看以下type字段SceneNode

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

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

RectangleNode
EllipseNode
PolygonNode
StarNode
VectorNode
BooleanOperationNode
于 2021-09-13T20:57:41.167 回答