【问题标题】:Why is the import for my custom package pointing only to the TS definition? [duplicate]为什么我的自定义包的导入只指向 TS 定义? [复制]
【发布时间】:2021-12-12 18:15:10
【问题描述】:

我已经创建并发布了一个包到 NPM,但是,当我使用 import { func } from 'module' 时,它给出了错误 TypeError module.func is not a function。

为什么只指向定义?

assertions.d.ts

declare namespace Chaiify {
  interface ChaiVerify {
    /** definition removed to condense code block*/
    verifyElement(parameters: object): void;

    /** definition removed to condense code block*/
    verifyElement<T>(parameters?: T): void;
  }
}

declare const chaiify: Chaiify.ChaiVerify;

declare module "chai-ify" {
  export = chaiify;
}

assertions.js

function verifyElement(parameters) { ... }

export default {
  verifyElement,
};

**.spec.js

import { verifyElement } from 'chai-ify'

verifyElement({ parameters }) { ... }

【问题讨论】:

  • import { func }?我没有看到 func 在任何地方导出...

标签: javascript typescript ecmascript-6 import cypress


【解决方案1】:

我在这篇文章中找到了答案:TypeScript export/import function

尝试改变

export default function sendEmail

只是

export function sendEmail

感谢https://stackoverflow.com/users/115686/tarling

【讨论】:

  • 如果另一个问题的答案回答了您的问题,这意味着您的问题是重复的。这不是一件坏事,但请不要复制答案,因为我们有一个标记重复的系统:-)
猜你喜欢
  • 1970-01-01
  • 2023-01-28
  • 2021-03-17
  • 1970-01-01
  • 1970-01-01
  • 2017-11-29
  • 1970-01-01
  • 2015-03-16
  • 2019-09-07
相关资源
最近更新 更多