see sharper
see sharper

Reputation: 12035

typescript duplicate import of 'moment'

I am using momentjs in a typescript/React project. Currently I have these lines at the top of a file:

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

where Moment is the type of a moment, and moment is the moment object itself, e.g.:

let m: Moment = moment.now();

Now my typescript linter whinges: Multiple imports from 'moment' can be combined into one. (no-duplicate-imports)tslint(1).

However I can't work out how to do that. Not sure how to have the * and Moment in the same import line...

Upvotes: 2

Views: 555

Answers (1)

joy08
joy08

Reputation: 9652

As suggested by Aluan Haddad ,Try importing moment as default export. Then your importing will look fine using below

import moment, {Moment} from 'moment';

In your tsconfig.json ,you should have allowSyntheticDefaultImports :true

Upvotes: 4

Related Questions