0

This is my normal dummy data by '.js'
There is an array and export it.

const students = [
  {
    id: 1,
    name: 'Sean Grey',
    age: 24
  },
  {
    id: 2,
    name: 'Sllllean Grey',
    age: 224
  },
  {
    id: 3,
    name: 'Seansdajfklajs Grey',
    age: 2114
  }
];

export default students;

I want to export this dummy data checking typescript.
So I'm thinking use 'class' or 'interface'.
But I don't know the guide for this example. Could you recommend some advice for me?

1
  • That is an array of objects and has nothing to do with JSON which is a string data format Commented Oct 6, 2019 at 6:17

1 Answer 1

2

Sounds like you are looking for a way to declare an object structure and fields, which is what interface is for.

Example:

interface Student {
    id: number;
    name: string;
    age: number;
}

Usage:

const students: Student[] = [{
    id: 1,
    name: 'Sean Grey',
    age: 24
}];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.