2createStudio / postcss-sprites

Generate sprites from stylesheets.
MIT License
413 stars 50 forks source link

How to use with TypeScript? #46

Closed NN77 closed 8 years ago

NN77 commented 8 years ago

The same situation with

TypeError: sprites is not a function
...
import * as sprites from 'postcss-sprites';

const PROCESSORS = [
  ...
  sprites({
    stylesheetPath: `${TMP_DIR}/sprites`,
    spritePath: `${TMP_DIR}/sprites`
  })
];

but solution for TypeScript needed. Thanks in advance

vvasilev- commented 8 years ago

Since the plugin is an ES6 module the code below should fix your issue.

import sprites from 'postcss-sprites'
NN77 commented 8 years ago
Module ''postcss-sprites'' has no default export. (1192)
vvasilev- commented 8 years ago

Try this

import sprites = require('postcss-sprites').default;

// or

import sprites = require('postcss-sprites');

Useful article about Typescript's import.

NN77 commented 8 years ago

Still error, even though changing ts compilation to es6 in my tsconfig.

Cannot invoke an expression whose type lacks a call signature. (2349)
vvasilev- commented 8 years ago

The support of Typescript was added in ff4fd90086c22cf634c8b0934ec7e376caf7c4d3(v3.1.2). So now you can use the plugin as shown below.

import sprites = require('postcss-sprites');

const PROCESSORS = [
  ...
  sprites['default']({
    stylesheetPath: `${TMP_DIR}/sprites`,
    spritePath: `${TMP_DIR}/sprites`
  })
];