Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine import all with others?

Tags:

typescript

I am getting from TSLint:

Multiple imports from 'moment' can be combined into one. 

Guilty code:

import * as moment from 'moment'; import { Moment } from 'moment'; 

I have tried several variants without success (I have not found relevant example in docs):

import * as moment, { Moment } from 'moment'; import { * as moment, Moment } from 'moment'; import { * as moment, Moment as Moment } from 'moment'; 
like image 618
monnef Avatar asked Aug 14 '17 07:08

monnef


1 Answers

Be careful because:

import * as moment from 'moment' 

is different from

import moment from 'moment' 

Because the second imports only the namespace moment and everything within, but the first imports everything including function moment() that is out of the namespace. Correct import can be:

import * as moment from 'moment'; type Moment = moment.Moment; 
like image 72
Taras Avatar answered Sep 18 '22 05:09

Taras