匿名require语句的TypeScript类型

时间:2018-03-26 02:53:52

标签: node.js typescript express typescript-typings typescript2.0

我有很多这些需要调用来在我们的Express服务器中注册中间件:

app.use('/api/v1/seed_db', ac.allow('ROLE_ADMIN'), require('./routes/seed-db'));
app.use('/api/v1/email', require('./routes/email'));
app.use('/api/v1/changelog', require('./routes/changelog'));
app.use('/api/v1/acquisitions', require('./routes/acquisitions'));
app.use('/api/v1/assignments', require('./routes/assignments'));
app.use('/api/v1/caches', require('./routes/caches'));
app.use('/api/v1/comments', require('./routes/comments'));
app.use('/api/v1/db_indexes', ac.allow('ROLE_ADMIN'), require('./routes/db-indexes'));
app.use('/api/v1/export_file', require('./routes/export-file'));
app.use('/api/v1/import_file', require('./routes/import-file'));
app.use('/api/v1/notifications', require('./routes/notifications'));
app.use('/api/v1/phases', require('./routes/phases'));
app.use('/api/v1/prompts', require('./routes/prompts'));
app.use('/api/v1/responses', require('./routes/responses'));
app.use('/api/v1/test', require('./routes/test'));
app.use('/api/v1/users', require('./routes/users'));
app.use('/api/v1/roles', require('./routes/roles'));
app.use('/api/v1/categories', require('./routes/categories'));
app.use('/api/v1/functional_teams', require('./routes/functional-teams'));
app.use('/api/v1/work_streams', require('./routes/work-streams'));
app.use('/api/v1/defaultprompts', require('./routes/default-prompts'));
app.use('/api/v1/folders', require('./routes/folders'));
app.use('/api/v1/files', require('./routes/files'));
app.use('/api/v1/collaborations', require('./routes/collaborations'));
app.use('/api/v1/work_stream_folder', require('./routes/work-stream-folders'));

有没有什么好方法可以将这些需要的调用转换为import语句,以便用TypeScript获取正确的类型信息?

不幸的是,命名所有导入都是一种拖累,因为他们并不真正需要名称。

1 个答案:

答案 0 :(得分:1)

  

是否有任何好方法可以将这些需要调用转换为import语句,以便使用TypeScript

获取正确的类型信息

仅手动,例如:

app.use('/api/v1/email', require('./routes/email'));

成为

import email = require('./routes/email');
app.use('/api/v1/email', email);