[TypeScript]はじめの一歩

$ npm install typescript
$ tsc –V
Version 4.4.3

sample.ts

console.log("Welcome to TypeScript!")

$ tsc sample.ts

console.log("Welcome to TypeScript!");

webでtsを使用する

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
	<script src="sample.js"></script>
</head>
<body>
	<h1 class="bg-primary text-white p-2">Sample page</h1>
	<div class="container py-2">
		<p class="h5" id="target">wait...</p>
	</div>	
</body>
</html>

sample.ts

window.addEventListener('load', (event) => {
	let p = document.querySelector('#target')
	p.textContent = "This is message by typescript."
})

なるほど