✔ 코드를 작성할 때 formatting과 linting도 중요하지만 한가지 더 중요한 것은 Type checking이다
Type checking이란? 자바스크립트는 동적으로 타입이 정의되는 언어로 실행시간에 가서야 작성 된 변수의 타입을 알게 된다 그래서 미리 에러가 나지 않는다
( 실행 전에는 타입에러를 알 수가 없다 즉, 코드로 작성한 변수의 타입이 맞지 않아도 실행되는 순서에서 작성된 변수 중 타입 에러 있다는 사실을 알 수 있다는 것이다 )
TypeScript는 기본적으로 javascript로 컴파일되는 언어로, javascript에 타입 정의만 얹어놓은 것이라고 보면 된다 ( 타입 정의 빼면 그냥 javascript )
const someString = 'Hello'
const result = Math.log(someString);
console.log(result);
// @ts-check
const someString = 'Hello'
const result = Math.log(someString);
console.log(result);
// @ts-check
// Formatting, Linting, Type Checking
// Formatting : Prettier
// Linting : ESLint
// Type Checking : TypeScript
const http = require('http')
http.createServer((req, res)=>{
res.statuscode = 200
res.end('hello')
})
const port= 8000
server.listen(port, ()=>{
console.log("the server is listening at port : ${port}.")
})
TypeScript를 써서 프로젝트를 진행하려면 설정이 필요한데, TypeScript의 설정파일을 작성해야한다
{
"compilerOptions":{
"strict" : true
}
"include" : [
"src/**/*"
]
}
// @ts-check
const x = null //에러