Importing Chai in Typescript

房东的猫 提交于 2021-02-07 13:16:02

问题


I'm trying to use chai in typescript.

Chai's javascript example shows this as:

var should = require('chai').should();

I downloaded the type definition:

tsd install chai

...referenced the file, tried to import

/// <reference path='../typings/chai/chai.d.ts' />
import should = require('chai').should();

I get:

error TS1005: ';' expected

...any idea how to do this?


回答1:


The tests for the chai typings do the following:

import chai = require('chai');
var should = chai.should();

Does that work for you?




回答2:


import { should } from 'chai';
should();



回答3:


import { expect } from 'chai';
import 'chai/register-should';

to use both expect and should



来源:https://stackoverflow.com/questions/31531256/importing-chai-in-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!