xxxxxxxxxx
typescript is javascript with syntax for types to aviod bugs in development,
autocompletion on object.
//install
npm i -g typescript //install globally
// to see if it is install
tsc --help
xxxxxxxxxx
<script src="https://cdnjs.cloudflare.com/ajax/libs/typescript/4.8.3/typescript.min.js" integrity="sha512-ipipS8Je0Nf76mSbTGMnLwgpI023wQDvAoZQ90fEJ/5eqrVs0YpfTqjsa+EX44iT5IHThlAqsgq3L1l7lwZcpQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
xxxxxxxxxx
interface LabelledValue {
label: string;
}
function printLabel(labelledObj: LabelledValue) {
console.log(labelledObj.label);
}
let myObj = {size: 10, label: "Size 10 Object"};
printLabel(myObj);
xxxxxxxxxx
const user = {
firstName: "Angela",
lastName: "Davis",
role: "Professor"
}
console.log(user.firstName)
Property 'name' does not exist on type '{ firstName: string; lastName: string; role: string; }'.2339Property 'name' does not exist on type '{ firstName: string; lastName: string; role: string; }'.Try
xxxxxxxxxx
const user = {
firstName: "Angela",
lastName: "Davis",
role: "Professor",
}
console.log(user.name)
Property 'name' does not exist on type '{ firstName: string; lastName: string; role: string; }'.
Property 'name' does not exist on type '{ firstName: string; lastName: string; role: string; }'.