2015-04-12 18 views
5

Sto incontrando un problema con:dattiloscritto 1.5: ES6 modulo predefinito di importazione di CommonJS 'export =' (.d.ts unico problema?)

import moment from 'moment'; 

moment stessa è una funzione che è un CommonJS predefinite esportazione, come codificato qui https://github.com/borisyankov/DefinitelyTyped/blob/master/moment/moment.d.ts:

interface MomentStatic { 
    (): Moment; 
    (date: number): Moment; 
    ... 
} 
declare var moment: moment.MomentStatic; 
declare module 'moment' { 
    export = moment; 
} 

La seguente non sembra funzionare:

import * from 'moment'; 
// error TS1005: 'as' expected. 
// error TS1005: 'from' expected. 

import moment from 'moment'; 
// error TS1192: External module ''moment'' has no default export. 

import {default as moment} from 'moment'; 
// error TS2305: Module ''moment'' has no exported member 'default'. 

La sintassi richiede ancora funziona ... ma sto cercando di evitarlo.

import moment = require('moment'); 

Pensieri?

+0

link per duplicare? –

risposta

18

La sintassi siete alla ricerca di

import * as moment from "moment"; 
+0

Funziona per me, grazie! –

+1

Siamo spiacenti, questo non è corretto, vedi http://stackoverflow.com/a/29598404/252087 –

+0

Grazie. Ho chiesto un chiarimento: https://github.com/Microsoft/TypeScript/issues/2242#issuecomment-92218146 – basarat

Problemi correlati