Import vs Require in Typescript

While I was looking through the Angular2 documentation, I came across the code below in here .

SRC / polyfills.ts

import 'core-js/es6';
import 'core-js/es7/reflect';
require('zone.js/dist/zone');

if (process.env.ENV === 'production') {
 // Production
} else {
 // Development
Error['stackTraceLimit'] = Infinity;
require('zone.js/dist/long-stack-trace-zone');
}

In the above code, we see that there are expressions importand require.

"core-js" and "zone.js" are node modules.

My question is: why is it importused for core-js and requirefor "zone.js", is there any specific reason for this?

+4
source share
1 answer

Using TypeScript, importyou can use it if there is a declaration file (see declaration files in the basarat book ) for the module.

, TypeScript , , require, .

+3

Source: https://habr.com/ru/post/1655600/


All Articles