Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

angular create object

export interface Student {
  name: string;
  section: string;
  phoneNumber: string;
}

export interface StudentDetails {
  [key: number]: Student; //Or string instead of number
}

And use it like this:

//Valid
let studentDetails: StudentDetails = {
  1: {
    name: 'Test Person1',
    section: 'Section 1',
    phoneNumber: '12345678'
  }
};

//Valid
studentDetails[2] = {
  name: 'Test Person 2',
  section: 'Section 2',
  phoneNumber: '87654321'
};

//Invalid (properties in UpperCase)
studentDetails[3] = {
  Name: 'Test Person 3',
  Section: 'Section 3',
  PhoneNumber: '52376724'
};

//Valid
let student: Student = studentDetails[2];
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript remove an item from array 
Typescript :: wordpress query to get posts by post meta 
Typescript :: ion modal dismiss 
Typescript :: test strategy vs test plan 
Typescript :: omit in typescript 
Typescript :: nginx ERR_TOO_MANY_REDIRECTS when i try redirect to https 
Typescript :: converting an image to base64 in angular 
Typescript :: typescript moment type 
Typescript :: how to update typescript in global 
Typescript :: recharts bar chart 
Typescript :: parsing error: unexpected token eslint typescript 
Typescript :: godot preload 
Typescript :: how to check if a string is composed only of alphabets in python 
Typescript :: check runnong ports ubuntu 
Typescript :: Typescript node start script 
Typescript :: type usestate typescript 
Typescript :: react typescript scss 
Typescript :: js split at index 
Typescript :: limit characters and have three dots after in angular 6 
Typescript :: Make Object properties Readonly TypeScript 
Typescript :: react native typescript template not working 
Typescript :: failed to enumerate objects in the container access is denied windows 10 
Typescript :: nested slots in vue 
Typescript :: create user objects firebase 
Typescript :: common mistakes 
Typescript :: td elements in same line 
Typescript :: typescript generic object 
Typescript :: disable out of stock products shopify 
Typescript :: typescript keyof typeof 
Typescript :: selenium multiple elements with same class name python 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =