TypeScript常见报错

TS1192: Module '"/Volumes/repos/tc-web-ts/node_modules/@types/react/index"' has no default export.javascript

把"allowSyntheticDefaultImports": true添加到tsconfig.jsonjava

TS7016: Could not find a declaration file for module 'rc-queue-anim'. '/Users/michealye/Desktop/myProduct/shebao520-mobile/node_modules/rc-queue-anim/lib/index.js' implicitly has an 'any' type.node

Try npm install @types/rc-queue-anim if it exists or add a new declaration (.d.ts) file containing declare module 'rc-queue-anim';react

Another two ways, when a module is not yours - just try install its from @types:web

npm install -D @types/module-name Or, if install errored - try rewrite import to require:typescript

// import * as yourModuleName from 'module-name'; const yourModuleName = require('module-name');express

TS7016: Could not find a declaration file for module '../styledComponents/loginAndRegister'. '/Users/michealye/Desktop/myProduct/shebao520-mobile/src/components/styledComponents/loginAndRegister.jsx' implicitly has an 'any' type.npm

没有指定类型 Edit your tsconfig.json "noImplicitAny": falsejson

TS1238: Unable to resolve signature of class decorator when called as an expression.bash

不能这样

@connect(mapStateToProps,mapDispatchToProps)

只能这样 export default connect( mapStateToProps, mapDispatchToProps )(LogTable)

TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.

In VSCode, Go to File => Preferences => Settings (or Control+comma) and it will open the User Settings file. Add "javascript.implicitProjectConfig.experimentalDecorators": true to the file and it should fix it.

in tsconfig.json

{ "compilerOptions": { "experimentalDecorators": true, "allowJs": true } }

TS1042: 'async' modifier cannot be used here.

Your usage is totally wrong. eg: async () => { /* ... */ }

TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option.

{ "compilerOptions": { "lib": [ "es2015" ] } }

TS2304: Cannot find name 'CSSStyleDeclaration'.

Adding "dom" to my compilerOptions.lib array in tsconfig.json did the trick.

TS1127 The issue is caused by a copy/past and just added a hidden invalid character. I rewrote the code manually from scratch everything work well now.

TS1005,TS1161,TS2352多数是由于文件后缀的致使的,快把ts改成tsx吧 ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts [tsl] ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts(5,13) TS1005: '>' expected.

ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts [tsl] ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts(5,14) TS1161: Unterminated regular expression literal.

ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts [tsl] ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts(6,1) TS1005: ')' expected.

ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts [tsl] ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts(5,8) TS2352: Type 'RegExp' cannot be converted to type 'App'.

ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts [tsl] ERROR in /Users/michealye/Desktop/myProduct/nodeStudy/styled-components-server-side-rendering/src/client/index.ts(5,8) TS2352: Type 'RegExp' cannot be converted to type 'App'. Property 'render' is missing in type 'RegExp'.

TS2345/TS2322: Argument of type '{ username: Key; }' is not assignable to parameter of type 'LoginXXX' TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. 多数是由于有一个地方没有区分类型吧 it is called not setting --strictNullCheck 😉. I would say it is desirable behaviour that if you have said that you want to make sure you don't have null values, that the type system becomes more strict. You can of course be explicit about it (x: any[] = []) and it works.

TS2322: Type '{ children: any; key: string; func: any; className: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes, HTMLDivElement>'. Property 'func' does not exist on type 'DetailedHTMLProps<HTMLAttributes, HTMLDivElement>'.

typescript不容许随便写HTML的属性,若是要自定义属性,须要加上data-*

TS2339: Property 'dataset' does not exist on type 'EventTarget'.

加个any

<div onClick={(e: any) => {
                    keyboardMessage[ e.target.dataset.func ]();
                }}>
复制代码

**TS2339: Property 'getBoundingClientRect' does not exist on type 'Element | Text'. Property 'getBoundingClientRect' does not exist on type 'Text'.

//原来是这样的
 ReactDOM.findDOMNode(this.thisRef).getBoundingClientRect();
 
//解决办法是这样的
    interface Node {
        getBoundingClientRect: () => any
    }
    const node:Node = ReactDOM.findDOMNode(this.thisRef) as Element;
    this.thisClientRect = node.getBoundingClientRect();
复制代码
相关文章
相关标签/搜索