简体   繁体   English

TypeScript:我可以使用“import * from”和“require(*)”进行混音

[英]TypeScript: Can I mix using “import * from” and “require(*)”

Is it ok in TypeScript to mix these too 'include' types? 在TypeScript中混合这些“包含”类型是否可以?

import { SomeType, someFunc } from "./MyThings";

And: 和:

import events = require('events');

The first would be a TypeScript module with an export or two... and the second is just a node module called events (I guess this could be anything pulled in from NPM too). 第一个是带有导出的TypeScript模块或两个...而第二个只是一个名为events的节点模块(我猜这可能是从NPM中提取的任何东西)。

Am I ok to mix these two conventions in a single TypeScript file? 我可以将这两个约定混合在一个TypeScript文件中吗?

Yes, this is acceptable in TypeScript. 是的,这在TypeScript中是可以接受的。

When using the import foo = require('foo'); 使用import foo = require('foo'); , you must have a module 'foo' declared with declare module 'foo' , typically in a .d.ts file. ,你必须有一个模块'foo'与申报declare module 'foo' ,通常在.d.ts文件。

This is typically covered in node.d.ts . 这通常包含在node.d.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在使用NextJS时不能在Javascript文件中导入或要求Typescript文件? - Why can I not import or require a Typescript file in a Javascript file while using NextJS? 如何使用 require() 在 typescript 中导入自定义文件? - How to import a custom file in typescript using require()? 打字稿2 - 使用ES6导入和要求? - Typescript 2 — using ES6 import & require? 如何使用参数导入类似node.js require的Typescript 1.0函数? - How can I import a Typescript 1.0 function like a node.js require with arguments? 如何在不导入或不需要的情况下使用 React Typescript 中路径中的图像? - How to use an image from a path in React Typescript without import or require? 为什么我不能在 typescript 中从 `export default {}` `import {}` - Why can't I `import {}` from `export default {}` in typescript 如何从 Typescript 包中的子文件夹导入? - How can I import from a subfolder in a Typescript package? 无法使用 require() 导入 Reactjs 中的图片 - Can't import pictures in Reactjs using require() 如何在不使用“需要”或“导入”的情况下导入NPM模块? - How do I import an NPM module without using 'require' or 'import'? 如何导入和使用方法描述在普通js文件中使用require js? - How can I import and use method describe using require js in normal js file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM