1

I am trying to import a variable from another file using and giving alias name for that but typescript throwing error alias name not defined.

Ex:

import { headerItems as TestHeader } from './headers';

Typescript version: 3.2.4
Ng cli: 7.3.7
webpack: 4.19.0

Thanks in advance!

7
  • use: import { headerItems } from './headers'; and create instance in the constructor Commented Apr 8, 2019 at 8:16
  • @PrashantPimpale that is working. my question is why alias name is not working. Commented Apr 8, 2019 at 8:17
  • 1
    developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Is it related to typescript or webpack? Commented Apr 8, 2019 at 8:18
  • Might be this will help:stackoverflow.com/a/39282290/7124761 Commented Apr 8, 2019 at 8:20
  • @niko yes its part of js. but in angular typescript will compile the code if i am not wrong Commented Apr 8, 2019 at 8:21

1 Answer 1

2

Refer https://github.com/angular/angular-cli/issues/13212 and https://github.com/IgorMinar/angular/commit/b7313ac2c619e96617258606d090f42ad73c44c0

It's unclear why import as results in the aliases to be undefined.

Plain tsc seems to do the right thing and emits the correct code, so it might be some kind of interaction in @angular/cli or webpack that are causing the failure.

This should be investigated separately from the tsc update in angular/angular. See angular/angular-cli#13212

-- Igor Minar

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

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.