Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Typescript中使用CSSNext并避免令人讨厌的;错误TS2349“;打字方式_Javascript_Typescript_Visual Studio Code_Tsd_Postcss - Fatal编程技术网

Javascript 如何在Typescript中使用CSSNext并避免令人讨厌的;错误TS2349“;打字方式

Javascript 如何在Typescript中使用CSSNext并避免令人讨厌的;错误TS2349“;打字方式,javascript,typescript,visual-studio-code,tsd,postcss,Javascript,Typescript,Visual Studio Code,Tsd,Postcss,对不起,如果这个问题已经问了又问。但我一直在点击这个讨厌的“错误TS2349”,每次我想在我的Typescript项目中使用外部节点包时,什么还没有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",

对不起,如果这个问题已经问了又问。但我一直在点击这个讨厌的“错误TS2349”,每次我想在我的Typescript项目中使用外部节点包时,什么还没有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);
我得到的:(

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;
真正的问题是

在这种情况下,“错误TS2349”在英语中的意思是什么?我如何编写mad maxTypeScript定义来修复此错误和相关错误:

我喜欢打字脚本的方式,但其他时候:(

**答复**

在下面的帮助下,解决此问题的代码是:

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的起点。

此定义

declare module "cssnext" {}
declare function cssnextLib(str: any,ops:Object): string | Object;
表示有一个名为
“cssnext”
的模块没有成员。这是当您从“cssnext”将
import*作为cssnextLib写入时导入的类型;
。您在上述定义中编写的
cssnextLib
函数被
import
隐藏,因此您无法看到它

你应该写的是:

declare module "cssnext" {
    function cssnextLib(str: any,ops:Object): string | Object;
    export = cssnextLib;
}

嘿,Ryan,我认为与问题中所描述的不同,
cssnext
库中的函数是,而不是
cssnextLib
。名称
cssnextLib
在模块声明之外不可见哦,是的,我的错。我被搞糊涂了,因为
import*是“cssnext”中的cssnextLib
。我没有注意到
导出=
。我认为它应该使用默认导入,然后从“cssnext”
导入cssnextLib;
?@ryan cavanaugh这不是我的错,不是David,我cssnextLib不是cssnext,因此不应该在定义文件中:),但您的解决方案打开了一个新的错误TS2497:Module'cssnext''解析为非模块实体,无法使用此构造导入。如果现在应用于上面:(必须在“cssnext”声明中添加
命名空间cssnextLib{}
declare module "cssnext" {
    function cssnextLib(str: any,ops:Object): string | Object;
    export = cssnextLib;
}