Answers for "typescript "variable?: type" notation"

0

typescript "variable?: type" notation

// the "last" property is optional and can be undefined
function printName(obj: { first: string; last?: string }) {  // ...}// Both OKprintName({ first: "Bob" });printName({ first: "Alice", last: "Alisson" });Try
Posted by: Guest on May-12-2021
0

typescript "variable!: type" notation

// Writing ! after any expression is effectively a type assertion 
// that the value isn’t null or undefined
function liveDangerously(x?: number | null) {  // No error  console.log(x!.toFixed());}Try
Posted by: Guest on May-12-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language