TypeScript常见报错

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

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

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.

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

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

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

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

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.

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

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

不能这样

@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.

你可能感兴趣的:(TypeScript常见报错)