Comportamiento esperado:
Espero que mi código se compile sin errores
Y esperando que la declaración de importación funcione
Comportamiento real:
Cuando ejecuto tsc app.ts, aparece este error:
../node_modules/@types/bluebird/index.d.ts:750:72 - error TS2583: No se puede encontrar el nombre 'Mapa'. ¿Necesitas cambiar tu biblioteca de destino? Intente cambiar la opción del compilador lib
a es2015 o posterior.
750 apoyos estáticos
También recibo otro error en mi editor de código:
El archivo '/Users/harry.gothold/Documents/api-call-weather/src/app.ts' no es un módulo.
Esta es la prueba que intento ejecutar:
'
importar * como aplicación desde '../src/app';
// importar * como chai de 'chai';
// importar {resultado} de '../app';
var chai = require ('chai');
var sinon = require ('sinon');
const esperar = chai.expect;
describir ('resultado', función () {
it ('debería llamarse con weatherDescription', (hecho) => {
esperar (resultado) .to.eventually.equal ('cielo despejado');
hecho();
});
}); `
Este es el código ts original:
`let request = require ('solicitud');
let promise = require ('pájaro azul');
function getData () {
devolver nueva promesa ((resolver: cualquiera, rechazar: cualquiera) => {
request ('https://api.openweathermap.org/data/2.5/forecast?id=2643743&APPID=99eaec08987344591490f9a6ee213155', {json: true},
(err: cualquiera, res: cualquiera, cuerpo: cualquiera) => {
resolver (body.list [0] .weather [0] .description);
rechazar (err, 'Lo siento, hubo un error al obtener los datos');
});
});
};
resultado de la función (weatherDescription: any) {
console.log ( The weather today is ${weatherDescription}
);
}
obtener datos()
.entonces ((weatherDescription: any) => {
resultado (weatherDescription)
})
.catch ((err: cualquiera) => {
tirar (err)
});
module.exports = {
getData: function () {},
resultado: función () {}
} `
Y este es mi archivo tsconfig:
`{
"compilerOptions": {
/ * Opciones básicas /"target": "es6", / Especifique la versión de destino de ECMAScript: 'ES3' (predeterminado), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018' o 'ESNEXT'. /"module": "commonjs", / Especifique la generación del código del módulo: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015' o 'ESNext'. /"lib": ["es5", "es6", "dom"], / Especifica los archivos de la biblioteca que se incluirán en la compilación. /// "allowJs": true, / Permitir que se compilen archivos javascript. /// "checkJs": verdadero, / Informar errores en archivos .js. /// "jsx": "preserve", / Especifica la generación de código JSX: 'preserve', 'react-native' o 'react'. /// "declaración": verdadera, / Genera el archivo '.d.ts' correspondiente. /// "DeclarationMap": verdadero, / Genera un mapa fuente para cada archivo '.d.ts' correspondiente. /// "sourceMap": verdadero, / Genera el archivo '.map' correspondiente. /// "outFile": "./", / Concatenar y emitir salida a un solo archivo. /// "outDir": "./", / Redirigir la estructura de salida al directorio. /// "rootDir": "./", / Especifica el directorio raíz de los archivos de entrada. Úselo para controlar la estructura del directorio de salida con --outDir. /// "compuesto": verdadero, / Habilitar la compilación del proyecto /// "removeComments": verdadero, / No emite comentarios a la salida. /// "noEmit": verdadero, / No emite salidas. /// "importHelpers": true, / Importar ayudantes de emisión de 'tslib'. /// "downlevelIteration": true, / Proporcionar soporte completo para iterables en 'for-of', spread y desestructuración cuando se dirigen a 'ES5' o 'ES3'. /// "isolatedModules": verdadero, / Transpile cada archivo como un módulo separado (similar a 'ts.transpileModule'). * /
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
} `
Dirija preguntas como esta a Stack Overflow.