Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
Typescript 智能感知:为什么可以';我不能查找DOM/CSS类型吗?_Typescript_Intellisense - Fatal编程技术网

Typescript 智能感知:为什么可以';我不能查找DOM/CSS类型吗?

Typescript 智能感知:为什么可以';我不能查找DOM/CSS类型吗?,typescript,intellisense,Typescript,Intellisense,在编写我的第一个TypeScript项目时,编译器非常挑剔: let test = <div style={{textAlign:'right'}}>Text</div>; // OK let right = 'right'; let test2 = <div style={{textAlign:right}}>Text</div>; /***ERROR*** Type '{ style: { textAlign: string; }; }

在编写我的第一个TypeScript项目时,编译器非常挑剔:

let test = <div style={{textAlign:'right'}}>Text</div>; // OK

let right = 'right';
let test2 = <div style={{textAlign:right}}>Text</div>; /***ERROR***
   Type '{ style: { textAlign: string; }; }' is not assignable to 
   type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
    Type '{ style: { textAlign: string; }; }' is not assignable to type 
    'HTMLAttributes<HTMLDivElement>'.
     Types of property 'style' are incompatible.
      Type '{ textAlign: string; }' is not assignable to type 'CSSProperties'.
       Types of property 'textAlign' are incompatible.
        Type 'string' is not assignable to type 'TextAlignProperty'.
*/
但有一个更简单的方法:

let right = 'right';
let test = <div style={{textAlign:right} as any}>Text</div>;
let right='right';
让测试=文本;

因此,这里真正的问题是,在不知道定义它的模块名称的情况下,如何查找某个对象。这将打开显示预期类型的d.ts文件,然后您可以进一步深入该文件:

或使用直接按名称跳转到类型:


如果你有
让test=…
,这怎么有效?它是否应该用引号引起来作为字符串?我认为IDE需要一个.html文件来获取它并提供代码hinting@Ryan这是JSX代码(为流行的React框架而发明),当您的文件扩展名为.tsx时,TypeScript支持它。虽然它是一个.ts文件,但我知道,您必须搜索
#textalingproperty
,而不是
@textalingproperty
。谢谢
let right = 'right';
let test = <div style={{textAlign:right} as any}>Text</div>;