typescript - How to import moment types definitions -
i have made angular 1 project typescript using yeoman generator: https://github.com/fountainjs/generator-fountain-systemjs
uses systemjs , jspm dependencies npm type definitions (using definitelytyped repository).
i have been struggling these last few days trying import moment type definitions. have installed moment using jspm, , have discovered comes own type definitions, if call command npm install @types/moment --save-dev
stub , deprecation warning
this stub types definition moment (https://github.com/moment/moment). moment provides own type definitions, don't need @types/moment installed!
now, don't know if it's editor, project or typescript settings or typescript issue, can't seem able import moment's type definitions.
if either import moment 'moment';
or import * moment 'moment';
error on editor (atom atom-typescript, have same error on visual studio code) cannot find module 'moment'.
despite error, when build application works fine (calling moment functions works).
i have tried lot of solutions found on internet (apparently, importing type definitions moment common issue) none worked. yesterday managed make work manually creating directory moment
inside node_modules/@types
, put moment.d.ts
inside (i had rename index.d.ts
though).
since didn't solution, wanted @ least create types folder put stuff without having modify node_modules
structure. created folder custom-types
, put moment
folder types definitions there, added custom-types
tsconfig.json
, thought would've worked fine error reappeared...
now i'm out of ideas, , don't know else try.
this current tsconfig.json
(in last attempt make things work have added custom-types
folder different paths, although it's on same level node_modules
folder , tsconfig.json
file)
{ "compileroptions": { "sourcemap": true, "emitdecoratormetadata": true, "experimentaldecorators": true, "removecomments": false, "noimplicitany": false, "module": "system", "target": "es5", "moduleresolution": "classic", "typeroots": [ "node_modules/@types/", "./custom-types/", "custom-types/", "../custom-types/", "../../custom-types/", "../../../custom-types/" ], "types": [ "angular-ui-router", "angular", "angular-mocks", "jquery", "jasmine", "moment", "es6-shim" ] }, "compileonsave": false, "filesglob": [ "custom-types/**/*.ts", "src/**/*.ts", "src/**/*.tsx", "!jspm_packages/**", "!node_modules/**" ] }
i've been using moment
in typescript (intellij) no work install typings it.
here's relevant configuration:
- inside
tsconfig.json
:"moduleresolution": "node"
- no
"types"
section @ all
./package.json
has no@types/moment
- inside
./node_modules/moment/
:./moment.d.ts
exists./package.json
has"typings": "./moment.d.ts"
./package.json
"version": "2.14.1"
when switch "moduleresolution": "classic"
, typescript says cannot find module 'moment'
. culprit.
Comments
Post a Comment