Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use FabricJs with TypeScript?

Im new in JS and want to rotate, change scale of images on canvas and coding in TypeScript using Fabric.js. as import to typescript is different with JavaScript so want to know how to import it to TypeScript. any links?

I install it like npm

install --save @types/fabric

import {fabric} from 'fabric';

And after grunt files to js there show the error:

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.

Any solutions for solve this problem?

like image 803
muze Avatar asked Oct 15 '18 01:10

muze


1 Answers

Based on the test file, it looks like the expected import is:

import { fabric } from "fabric";
like image 51
Matt McCutchen Avatar answered Oct 14 '22 07:10

Matt McCutchen