![](/img/trans.png)
[英]NextJS Typescript - Setup tslint configuration to force error when have unused import/declarations
[英]Force typescript not to remove unused references
请检查我在github上的演示项目 。
在我的react-tfractal / tests / component / tfractal.spec.tsx测试中:
import * as React from 'react';
import * as ReactTestUtils from 'react-addons-test-utils';
import {expect} from 'chai';
import {Tfractal} from '../../src/tfractal';
var R = React;
describe('tfractal', function () {
it('renders', function () {
var tfractal = ReactTestUtils.renderIntoDocument(<Tfractal />);
expect(tfractal).exist;
});
});
从不使用React
导入,但是react-addons-test-utils
要求使用React
导入(如果没有React
导入,我会收到一条错误消息“未定义反应”)。 问题是:没有线
var R = React;
此导入由打字稿编译器删除。
该
import 'react'
不会被删除但无法正常工作(相同的错误消息“未定义反应”)。
如何在不创建虚拟变量的情况下解决该问题?
跑
npm install
tsd install
npm run test
去检查。
我不明白为什么会这样,但是尝试添加以下内容:
global.React = React
甚至这可能有效:
React;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.