记录报错

文章讲述了在使用TypeScript时遇到的问题,如安装gtypescript的报错、配置文件中`allowJs`选项的设置、AbortSignal类型的冲突,以及在引入React时的模块导入错误。主要讨论了TypeScript的编译时机和配置注意事项。
摘要由CSDN通过智能技术生成

1. ts

`npm install -g typescript
查看版本:tsc -v`

2. zsh: command not found: tsc npm install -g typescript

3. 报错 修改完成 关闭配置文件并且重新运行文件

File 'test.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? The file is in t

{
  "compilerOptions": {
    "allowJs": true,
    // 其他配置项...
  }
  // 其他配置项...
}

4. 报错 npm install@types/node -D 重启项目

image.png

Subsequent variable declarations must have the same type.  Variable 'AbortSignal' must be of type '{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; timeout(milliseconds: number): AbortSignal; }', but here has type '{ new (): AbortSignal; prototype: AbortSignal; }'.

![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8ad7757fbb054be3816567ee8d99268d~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image#?w=1640&h=590&s=572162&e=png&b=202020)
72 declare var AbortSignal: {
               ~~~~~~~~~~~

  ../../../../../../usr/local/lib/node_modules/typescript/lib/lib.dom.d.ts:2337:13
    2337 declare var AbortSignal: {
                     ~~~~~~~~~~~
    'AbortSignal' was also declared here.


Found 1 error in node_modules/@types/node/globals.d.ts:72

image.png

5. ts文件运行

tsc test.ts

会生成一个js文件 .ts => .js => 浏览器执行环境
问题:ts的类型检测和语法检测在什么时间? 在编译时

6. # 在引入React时为什么会出现“cannotuseimportstatementoutsideamodule”的错误

image.png
npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env

在 Django 中,我们可以使用日志记录记录应用程序中出现的错误信息。当应用程序发生错误时,我们可以使用 logging.error() 方法记录错误信息,并将错误信息写入到指定的日志文件中。 以下是一个简单的 Django 日志配置示例,该配置指定了一个名为 "file" 的日志处理器,并将其绑定到了 "django" 这个 logger 上。在这个配置中,我们设置日志级别为 ERROR,表示只有 ERROR 级别及以上的日志才会被记录下来,并将错误日志写入到指定的文件中。 ```python LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'class': 'logging.FileHandler', 'filename': '/path/to/error.log', }, }, 'loggers': { 'django': { 'handlers': ['file'], 'level': 'ERROR', }, }, } ``` 如果我们想在代码中记录错误信息,在应用程序中捕获异常并使用 logging.error() 方法记录错误信息即可,例如: ```python import logging logger = logging.getLogger(__name__) def my_view(request): try: # some code that may raise an exception except Exception as e: logger.error('Error occurred: %s', e) ``` 在这个例子中,我们在应用程序的某个函数中使用 try/except 语句来捕获可能出现的异常,并使用 logging.error() 方法记录错误信息。在记录错误信息时,我们可以使用 %s 格式化字符串来将异常信息作为参数传递给 logging.error() 方法。 通过这种方式记录错误信息,我们可以在日志文件中查看应用程序出现的错误信息,从而更好地管理和维护我们的 Django 应用程序。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值