如果这个问题有豆子问,很抱歉。但是我不停地点击这个讨厌的"error TS2349",每次我想在类型记录项目中使用外部节点包时,什么还没有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定义来修复这个定义和相关的定义。:)
我喜欢键入脚本的方式,但其他时候:
**回答**
在下面代码的帮助下解决这个问题的方法是:
declare module "cssnext" {
function cssnext(str: string,ops:Object): string | Object;
export default cssnext;
}
import * as cssnext from "cssnext";
let cssnext(str,op)可能不是100%的下一次投诉,但这是TSD的起点。
发布于 2015-11-12 18:43:25
这个定义
declare module "cssnext" {}
declare function cssnextLib(str: any,ops:Object): string | Object;说有一个名为"cssnext"的模块,它没有成员。这是在编写import * as cssnextLib from "cssnext";时导入的类型。您在上述定义中编写的cssnextLib函数被import隐藏(隐藏),因此您看不到它。
你应该写的是:
declare module "cssnext" {
function cssnextLib(str: any,ops:Object): string | Object;
export = cssnextLib;
}https://stackoverflow.com/questions/33678757
复制相似问题