How can moment.js be imported with typescript?

后端 未结 7 1546
-上瘾入骨i
-上瘾入骨i 2020-11-30 09:51

I\'m trying to learn Typescript. While I don\'t think it\'s relevant, I\'m using VSCode for this demo.

I have a package.json that has these pieces in it

相关标签:
7条回答
  • 2020-11-30 10:20

    Update

    Apparently, moment now provides its own type definitions (according to sivabudh at least from 2.14.1 upwards), thus you do not need typings or @types at all.

    import * as moment from 'moment' should load the type definitions provided with the npm package.

    That said however, as said in moment/pull/3319#issuecomment-263752265 the moment team seems to have some issues in maintaining those definitions (they are still searching someone who maintains them).


    You need to install moment typings without the --ambient flag.

    Then include it using import * as moment from 'moment'

    0 讨论(0)
提交回复
热议问题