0

I am used to this TypeScript import statement, which imports the "Component" class from the "angular/core" module:

import {Component} from '@angular/core';

But I have also seen other import statements such as this:

import 'core-js/es6/symbol';

What does the second one do, exactly?

2 Answers 2

2

In the documentation it's called Import a module for side-effects only:

Though not recommended practice, some modules set up some global state that can be used by other modules. These modules may not have any exports, or the consumer is not interested in any of their exports.

In the example you posted this import probably adds the Symbol es6 polyfill so that the compiler will find it even without targeting es6

Sign up to request clarification or add additional context in comments.

Comments

1

The second references a javascript file directly, \node_modules\core-js\es6\symbol.js in this case, and any export statements in that file will be loaded into your program.

symbol.js looks like this:

require('../modules/es6.symbol');
require('../modules/es6.object.to-string');
module.exports = require('../modules/_core').Symbol;

So you are getting the .Symbol object from the _core.js module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.