【发布时间】:2023-03-18 00:14:01
【问题描述】:
我想在由 react-scripts 生成的文件中导入类型。
我创建了this minimal repo 来显示问题。
到目前为止我有这个:
// import * as React from 'react';
// import { MemoryHistory } from 'history';
// import { RenderResult } from 'react-testing-library';
interface Window {
env: any;
}
type ContextDefaultValue = [string, (val: string) => void];
/* global function for rendering with Router */
declare function renderWithRouter(ui: any, { route, history, }?: {
route?: string;
history?: any;
}): any;
如果我取消注释任何导入语句并运行 tsc,则 renderWithRouter 不再位于全局命名空间中,并且我收到此错误:
找不到名称“renderWithRouter”。
我不能在 .d.ts 文件中导入类型吗?
【问题讨论】:
-
能否提供一个最小的 github 项目来重现该问题?
-
@Mu-TsunTsai 我创建了这个 repo 来说明问题github.com/dagda1/fooky-types
-
抱歉,我无法重现您的问题。以下是我采取的步骤: (1) 下载 repo 并使用 VS Code 打开。 (2) 运行
npm install。 (3) 运行npm run build。没有错误发生,成功生成“build”文件夹。 -
运行 tsc build 也不会产生任何错误,只是没有生成任何东西。
-
来自我发送的链接中的回购?
标签: typescript