I created an angular 1 project with typescript using this yoma generator: https://github.com/FountainJS/generator-fountain-systemjs
It uses SystemJS and jspm to get dependencies, but npm for type definitions (using the DefinitelyTyped repository).
I have been trying these last few days to try to import moment type definitions . I set the moment using jspm and I found that it has its own type definitions, so if you call the command npm install @types/moment --save-dev
you only get a stub and a warning about failure
This is the definition of stub types for Moment ( https://github.com/moment/moment ). Moment provides its own type of definition, so you do not need @ types / moment set!
Now I don’t know if my settings of the editor, project or typescript are really typescript problem, but I can not import moment type definitions correctly.
If I do either import moment from 'moment';
or import * as moment from 'moment';
, I get this error in my editor (atom with typescript atom, but I have the same error in Visual Studio code)Cannot find module 'moment'.
Despite this error, when I create my application, it works fine (the moment-calling functions work).
, (, - ), .
, moment
node_modules/@types
moment.d.ts
( index.d.ts
).
, , , , node_modules
. custom-types
moment
, custom-types
tsconfig.json
, , , ...
, , .
tsconfig.json
( - custom-types
, , node_modules
tsconfig.json
)
{
"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/**"
]
}