31
loading...
This website collects cookies to deliver better user experience
TypeScript is not a brand new language! TypeScript is a super-set of JavaScript, which means you can still use the same syntax you have used in JavaScript!
//app.js
let num = 3
console.log(typeof num) // this will print number
num = "I am String"
console.log(typeof num) // this will print string
But sometimes this weirdness can driving you crazy?
Sometimes you probably have ended up spending hours behind the undefined error, Silly mistakes (Datatype mismatch).
// app.jsx
// this is valid
<Component name="Darshan!" />
// this is invalid but JavaScript won't show any error
<Component name={123} />
JavaScript will not complaint if you have passed number value instead of string. It will print that value on browser.
TypeScript is use to make enterprise level web applications, which is powered by Microsoft!
// app.ts
// Narrowed down type to string
let name:string = "Darshan"
// This will show you the error
name = 123
You don't have to explicitly define type every time. TypeScript can implicitly define type based on right hand side value.
app.ts
const name = "I am String"
// This will still show you the error!
name = 8923
TypeScript is Compile time Language.
You cannot run TypeScript on Browser directly. You need babel compiler that convert your TypeScript to JavaScript code.
You can also create your own Type!
To narrowed down your props/state you need to know the particular type.
You need to configure project before you start writing code in TypeScript.