当前位置:网站首页>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/
}
]
}
}
边栏推荐
- Error occurred while trying to proxy request The project suddenly can't get up
- Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
- Go 学习笔记(84)— Go 项目目录结构
- 【愚公系列】2022年07月 Go教学课程 016-运算符之逻辑运算符和其他运算符
- 【多线程】
- MySQL database (basic)
- WMware Tools安装失败segmentation fault解决方法
- [Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
- WMware Tools installation failed segmentation fault solution
- XSS related knowledge
猜你喜欢

C language force buckles the rotating image of the 48th question.auxiliary array

go mode tidy出现报错go warning “all“ matched no packages

WMware Tools安装失败segmentation fault解决方法

binglog log tracking: data backup and backup tracking

How to import game archives in joiplay emulator

神经网络(ANN)

web漏洞之需要准备的工作

Error occurred while trying to proxy request The project suddenly can't get up

mysql索引失效的常见9种原因详解
How to ensure the consistency of database and cache data?
随机推荐
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
What is Promise?What is the principle of Promise?How to use Promises?
神经网络(ANN)
加密传输过程
asser利用蚁剑登录
SereTOD2022 Track2 Code Analysis - Task-based Dialogue Systems Challenge for Semi-Supervised and Reinforcement Learning
MySQL中substring与substr区别
C language force buckles the rotating image of the 48th question.auxiliary array
MySQL Series 1: Account Management and Engine
WMware Tools installation failed segmentation fault solution
[C language course design] C language campus card management system
binglog log tracking: data backup and backup tracking
Summary of MySQL database interview questions (2022 latest version)
XSS相关知识
The difference between substring and substr in MySQL
【Demo】ABAP Base64加解密测试
数据库的严格模式
MySQL notes under
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
IOT cross-platform component design scheme