我确实启用了严格的编译器规则,该规则禁止使用隐式any
类型( tsconfig.json 中的"noImplicitAny": true
)。在禁用此规则的情况下,如果不提供类型,则代码可以正常工作,并且工作如下:
import * as csurf from 'csurf'; // Import everything as "csurf".
const expressApp: Express = express(); // Create Express instance.
expressApp.use(csurf()); // Enable CSRF protection. Must be after sessions and cookies security.
但是,启用此编译器规则后,出现以下错误ERROR in path\to\app\server\main.ts(5,24) TS7016: Could not find a declaration file for module 'csurf'. 'path\to\app\node_modules\csurf\index.js' implicitly has an 'any' type.