如何在TypeScript中使用FabricJs?

时间:2018-10-15 01:54:11

标签: typescript canvas fabricjs

我是JS的新手,并且想要旋转,更改画布上图像的比例以及使用Fabric.js在TypeScript中进行编码。由于导入到Typescript与JavaScript不同,因此想知道如何将其导入到TypeScript。任何链接?

我像npm一样安装

  

安装--save @ types / fabric

import {fabric} from 'fabric';

在向js发出grunt文件后,显示错误:

MacBook-Pro:someName mmmr$ grunt
(node:3965) ExperimentalWarning: The http2 module is an experimental API.
Running "typescript:test" (typescript) task
> src/someName.ts(20,26): error TS1147: Import declarations in a namespace cannot reference a module.
> src/someName.ts(20,26): error TS2307: Cannot find module 'fabric'.
> src/import.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
> src/import.ts(1,24): error TS2307: Cannot find module 'fabric'.
Warning: Task "typescript:test" failed. Use --force to continue.
Aborted due to warnings.

有解决此问题的解决方案吗?

1 个答案:

答案 0 :(得分:0)

基于the test file,看起来预期的导入是:

import { fabric } from "fabric";