当前位置:网站首页>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/
}
]
}
}
边栏推荐
猜你喜欢
随机推荐
牛客网刷题训练(四)
Preparations for web vulnerabilities
How to Add a Navigation Menu on Your WordPress Site
【Yugong Series】July 2022 Go Teaching Course 019-For Circular Structure
GO GOPROXY代理设置
ES 中时间日期类型 “yyyy-MM-dd HHmmss” 的完全避坑指南
A complete guide to avoiding pitfalls for the time-date type "yyyy-MM-dd HHmmss" in ES
The difference between truncate and delete in MySQL database
MySQL grant statements
MySQL数据库进阶篇
Understand from the 11 common examples of judging equality of packaging types in the written test: packaging types, the principle of automatic boxing and unboxing, the timing of boxing and unboxing, a
MySql数据恢复方法个人总结
DNS resolution process [visit website]
How to ensure the consistency of database and cache data?
Oracle一个诡异的临时表空间不足的问题
Mysql体系化之JOIN运算实例分析
如何在WordPress网站上添加导航菜单
MySQL数据库(基础)
Gabor滤波器学习笔记
消息队列存储消息数据的MySQL表设计








