我是 Typescript 和 NodeJs 的新手。每当我package.json在导入node 模块时提到node 模块,我总是收到以下错误。
Could not find a declaration file for module 'ini'. 'e:/typescript-2020-1/parser1/node_modules/ini/ini.js' implicitly has an 'any' type.
Try `npm install @types/ini` if it exists or add a new declaration (.d.ts) file containing `declare module 'ini';`
Could not find a declaration file for module 'json-query'. 'e:/typescript-2020-1/parser1/node_modules/json-query/index.js' implicitly has an 'any' type.
Try `npm install @types/json-query` if it exists or add a new declaration (.d.ts) file containing `declare module 'json-query';`
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我总是在下面搜索并安装以下内容package.json。
"dependencies": { …Run Code Online (Sandbox Code Playgroud) 我对 Typescript 比较陌生,在从该网站学习时,我了解到,yield 可以用于使用 for-await-of 进行异步迭代。下面是 Javascript 中的函数。请帮助我如何在 Typescript 类中使用。当我编写以下代码时,出现错误TS1163:“yield”表达式仅允许在生成器主体中使用。 我想在 Typescript 类中编写以下代码。
https://blog.bitsrc.io/keep-your-promises-in-typescript-using-async-await-7bdc57041308。
function* numbers() {
let index = 1;
while(true) {
yield index;
index = index + 1;
if (index > 10) {
break;
}
}
}
function gilad() {
for (const num of numbers()) {
console.log(num);
}
}
gilad();
Run Code Online (Sandbox Code Playgroud)
我也尝试在 Typescript 类中编写,但它给出了编译问题。
public getValues(): number {
let index = 1;
while(true) {
yield index;
index = index + 1;
if (index > 10) { …Run Code Online (Sandbox Code Playgroud) 我有一个有两个主要模块的应用程序。一个是ui-component,另一个是service-component。ui-component 使用 Winston 记录器,service-component 使用 pino 记录器。pino 记录器的链接是https://getpino.io/#/。我尝试使用以下代码,但看不到日志文件,甚至没有生成日志文件。服务组件用作 ui 组件内的节点模块,它使用 Electron、Angular 8 和 NodeJs。当我运行该命令时yarn start,应用程序将运行,并且我会进行一些验证以查看日志文件中的日志。
请帮助我,我是 NodeJs、Pino 的新手。两个不同的记录器实现是否可能会在 NodeJs 应用程序中产生任何冲突?
//import pino from "pino";
/*const dest = pino.extreme();
export const logger = pino(dest);*/
/*const dest = pino.destination('./logs/log')
export const logger = pino({ level: 'info' }, dest)*/
export const logger = require('pino')()
const tee = require('pino-tee')
const fs = require('fs')
const stream = tee(process.stdin)
stream.tee(fs.createWriteStream('myLogFile'), line => line.level >= 0)
stream.pipe(process.stdout)
logger.info('hello world') …Run Code Online (Sandbox Code Playgroud) 我正在学习 NodeJs 12 的Promise.allSettled()功能及其用法。我已经编写了以下代码。我能够在控制台中打印状态,但无法打印值,因为它给出了编译问题。
const p1 = Promise.resolve(50);
const p2 = new Promise((resolve, reject) =>
setTimeout(reject, 100, 'geek'));
const prm = [p1, p2];
Promise.allSettled(prm).
then((results) => results.forEach((result) =>
console.log(result.status,result.value)));
Run Code Online (Sandbox Code Playgroud)
我在 tsconfig.json 下面提供。
{
"compilerOptions": {
"target": "es2017",
"lib": ["es6","esnext", "dom"],
"allowJs": true,
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"typeRoots": [ "./types", "./node_modules/@types"]
},
"include": ["src"],
"exclude": ["**/__tests__/*"]
}
Run Code Online (Sandbox Code Playgroud) 我正在从以下站点学习 Promise.any。\n https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any \nIDE 不显示任何错误,但使用yarn命令运行时,出现以下错误。
\nE:\\typescript-2020-1\\promise-usages-1\\lib\\basics1\\promise-any.service.js:18 \n Promise.any([ \n ^ \nTypeError: Promise.any is not a function \n at PromiseAnyService.validateAll_Type1 (E:\\typescript-2020-1\\promise-usages-1\\lib\\basics1\\promise-any.service.js:18:17)\n at Object.<anonymous> (E:\\typescript-2020-1\\promise-usages-1\\lib\\test.js:35:7) \n at Module._compile (internal/modules/cjs/loader.js:1137:30) \n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) \n at Module.load (internal/modules/cjs/loader.js:985:32) \n at Function.Module._load (internal/modules/cjs/loader.js:878:14) \n at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) \n at internal/main/run_main_module.js:17:47 \n\xe2\x80\x89ERROR\xe2\x80\x89 Command failed with exit code 1. \n\n \nRun Code Online (Sandbox Code Playgroud)\n我写了简单的代码来测试。请帮助我在 Typescript 课程中做错的地方。
\nconst promise1 = Promise.reject(0);\nconst promise2 = new Promise((resolve) => setTimeout(resolve, 100, \'quick\'));\nconst promise3 = new Promise((resolve) => …Run Code Online (Sandbox Code Playgroud) node.js ×4
typescript ×4
javascript ×2
angular ×1
electron ×1
es6-promise ×1
logging ×1
npm ×1
promise ×1