【发布时间】:2016-02-14 05:01:09
【问题描述】:
对不起,如果这个问题有豆问和问。但是我总是遇到这个讨厌的 "error TS2349",每次我想在我的 Typescript 项目中使用 external Node Package 时,怎么办?还有一个 TypeScript 定义 :(
这是我当前的设置
node -v v5.0.0
tsc -v message TS6029: Version 1.6.2
OS: 4.1.12-1-ck GNU/Linux Arch
tsconfig {
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"noImplicitAny": false,
"outDir": "../lib",
"rootDir": ".",
"sourceMap": false
},
}
external node package : "cssnext": "^1.8.4"
我的主代码
/// <reference path="../definitions/tsd/node/node.d.ts" />
import * as fs from "fs";
import * as cssnext from "cssnext";
let source = "./index.css";
let output = cssnext(
fs.readFileSync(source, "utf8"),
{from: source}
);
fs.writeFileSync("dist/index.css", output);
我在寻找什么?
var cssnext = require("cssnext")
var fs = require("fs")
var source = "./index.css"
var output = cssnext(
fs.readFileSync(source, "utf8"),
{from: source}
)
fs.writeFileSync("dist/index.css", output)
我得到了什么:(
tsc -p ./src;
src/main.ts(36,14): error TS2349: Cannot invoke an expression whose type lacks a call signature.
** _reference.d.ts 有 **
declare module "cssnext" {}
declare function cssnext(str: any,ops:Object): string | Object;
真正的问题是
什么是英文中的“error TS2349”,在这种情况下,我该如何编写 mad max TypeScript 定义来修复这个问题和相关问题。 :)
我喜欢 Type Script 方式,但其他时候 :(
** 回答**
在下面的代码帮助下解决这个问题是:
declare module "cssnext" {
function cssnext(str: string,ops:Object): string | Object;
export default cssnext;
}
import * as cssnext from "cssnext";
let cssnext(str,op)
这可能不是 100% 的 cssnext 投诉,但它是 TSD 的起点。
【问题讨论】:
标签: javascript typescript visual-studio-code tsd postcss