Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report]: ts下control添加选项报错 #2067

Open
EmmanuelSR31 opened this issue Feb 13, 2025 · 1 comment
Open

[Bug Report]: ts下control添加选项报错 #2067

EmmanuelSR31 opened this issue Feb 13, 2025 · 1 comment

Comments

@EmmanuelSR31
Copy link

发生了什么?

ts下的代码
lf.extension.control.addItem({
key: 'selection',
iconClass: 'selection-icon',
title: '',
text: '选区',
onClick: (lf: LogicFlow) => {
lf.openSelectionSelect()
lf.once('selection:selected', () => {
lf.closeSelectionSelect()
})
}
})

打包时报错信息
类型“ExtensionDefinition | Extension”上不存在属性“addItem”。

代码包文件位置src\page\home\home.vue

代码.zip

logicflow/core版本

2.0.10

logicflow/extension版本

2.0.14

logicflow/engine版本

No response

浏览器&环境

No response

@EmmanuelSR31 EmmanuelSR31 added the bug Something isn't working label Feb 13, 2025
@ChangeSuger
Copy link
Collaborator

  • 不关闭ts类型检查的解决方案(推荐):
// 导入 Control,类型定义的时候会用到
import { Control } from '@logicflow/extension';

// 补充类型定义,这样打包的时候就不会报错
const control = lf.extension.control as Control;

control.addItem({
  key: 'selection',
  iconClass: 'selection-icon',
  title: '',
  text: '选区',
  onClick: (lf: LogicFlow) => {
    lf.openSelectionSelect()
    lf.once('selection:selected', () => {
      lf.closeSelectionSelect()
    })
  }
});
  • 关闭ts类型检查的解决方案:
// 确定代码没问题,只是类型检查报错,可以直接添加下面这一行来忽略某一行代码中的ts类型错误
// @ts-ignore
lf.extension.control.addItem({
  key: 'selection',
  iconClass: 'selection-icon',
  title: '',
  text: '选区',
  onClick: (lf: LogicFlow) => {
    lf.openSelectionSelect()
    lf.once('selection:selected', () => {
      lf.closeSelectionSelect()
    })
  }
});

@ChangeSuger ChangeSuger removed the bug Something isn't working label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants