当前位置:网站首页>TypeScript在使用中出现的问题记录
TypeScript在使用中出现的问题记录
2022-07-31 00:38:00 【百里狂生】
TypeScript
元组声明BUG
let list: [string, number] = ['hello', 123];
list.push('world'); // success
// 理论上是不可以给 list 添加任何元素的
setter, getter 编译需要支持 es5
# 编译成js文件便于执行
$ tsc app.ts
app.js
# 使用es5 的方式编译成js文件便于执行
$ tsc -t es5 app.ts
app.js
# 使用 node 执行js文件
$ node app.js
TypeScript 在 import 文件的时候提示文件不存在
// src/main.ts
import popup from './comoonents/popup/popup';
popup({
})
然后启动 npm run serve
报错,./components/popup/popup
文件不存在。
原因是需要在 webpack.config.js 中添加一行配置:
moduel.exports = {
mode: 'development',
entry: './src/main.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js'
},
devServer: {
},
resolve: {
// 需要调整 import 文件的查找顺序,这样才能让 webapck 打包的时候找到 .ts 文件的模块
extensions: ['.ts', '.js', '.json']
},
module: {
rules: [
{
test: /\.ts$/,
use: ['ts-loader'],
// 屏蔽 node_modules 中的 .ts 文件
exclude: /node_modules/
}
]
}
}
边栏推荐
- 【深度学习】Transformer模型详解
- Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.
- WMware Tools安装失败segmentation fault解决方法
- Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
- Restricted character bypass
- 网络常用的状态码
- Kotlin协程:协程上下文与上下文元素
- 从两个易错的笔试题深入理解自增运算符
- MySQL triggers
- A complete guide to avoiding pitfalls for the time-date type "yyyy-MM-dd HHmmss" in ES
猜你喜欢
Neural Network (ANN)
Shell编程之条件语句
Xss target drone training [success when pop-up window is realized]
【多线程】
Regular expression password policy and regular backtracking mechanism bypass
限制字符绕过
Gabor滤波器学习笔记
Homework: iptables prevent nmap scan and binlog
如何在WordPress网站上添加导航菜单
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
随机推荐
正则表达式密码策略与正则回溯机制绕过
MySQL master-slave replication and read-write separation script - pro test available
registers (assembly language)
【愚公系列】2022年07月 Go教学课程 019-循环结构之for
[Yugong Series] July 2022 Go Teaching Course 015-Assignment Operators and Relational Operators of Operators
[Deep learning] Detailed explanation of Transformer model
asser利用蚁剑登录
Ukraine's foreign ministry: wu was restored to complete the export of food security
Oracle一个诡异的临时表空间不足的问题
Encapsulate and obtain system user information, roles and permission control
Xss target drone training [success when pop-up window is realized]
GO GOPROXY代理设置
什么是Promise?Promise的原理是什么?Promise怎么用?
SereTOD2022 Track2 Code Analysis - Task-based Dialogue Systems Challenge for Semi-Supervised and Reinforcement Learning
论文理解:“Designing and training of a dual CNN for image denoising“
从两个易错的笔试题深入理解自增运算符
How to adjust Chinese in joiplay simulator
Error occurred while trying to proxy request项目突然起不来了
MySQL notes under
加密传输过程