Answers for "typescript interface"

29

typescript interface function

interface IEmployee {
    empCode: number;
    empName: string;
    getSalary: (number) => number; // arrow function
    getManagerName(number): string; 
}
Posted by: Guest on May-29-2020
6

typescript class interface

interface IPerson {
  name: string
  age: number
  hobby?: string[]
}

class Person implements IPerson {
  name: string
  age: number
  hobby?: string[]

  constructor(name: string, age: number, hobby: string[]) {
    this.name = name
    this.age = age
    this.hobby = hobby
  }
}

const output = new Person('john doe', 23, ['swimming', 'traveling', 'badminton'])
console.log(output)
Posted by: Guest on December-07-2020
2

typescript valueof interface

type ValueOf<T> = T[keyof T];
Posted by: Guest on April-29-2020
1

typescript interface

interface Foo {
    bar: string;
    qux: number;
}
// Creates object implementing interface:
const MyFoo = <Foo> {
    bar: "Hello",
    qux: 7
}
// Or:
const MyFoo: Foo = {
    bar: "Hello",
    qux: 7
}
Posted by: Guest on April-29-2021
1

typescript interface

// https://stackoverflow.com/a/41967120
// `I` Prefix not recommended : 
// Ref : https://stackoverflow.com/a/41967120, 
//       https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines
interface SquareConfig {
  color?: string;
  width?: number;
  [propName: string]: any;
}

interface StringArray {
  [index: number]: string;
}
 
let myArray: StringArray;
myArray = ["Bob", "Fred"];
 
let myStr: string = myArray[0];
Posted by: Guest on September-29-2021
1

typescript interface

interface LabeledValue {
  label: string;
}

function printLabel(labeledObj: LabeledValue) {
  console.log(labeledObj.label);
}

let myObj = { size: 10, label: "Size 10 Object" };
printLabel(myObj);Try
Posted by: Guest on December-07-2020

Code answers related to "typescript interface"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language