0

How to compare class (schema) to data of any type

for example:

schema class

class Element {
    name!: string
    age?: number
}
type DataType = Element[]

some variable

[
    {
        "name": "mike"
    },
    {
        "name": "john",
        "age": 14
    }
]

I want to know if the data matches the circuit description

  • What exactly do you mean by "compare"? – Alexander Apr 23 '21 at 00:17
  • @Alexander , I want to know if the data matches the circuit description – Levaya Pochta Apr 23 '21 at 00:22
  • ThereIt's... not a circuit? But anyways, I think the word you're looking for is "validate". Googling "json schema validation" should point you in the right direction – Alexander Apr 23 '21 at 00:28
  • @Alexander, yes, I want to write own validation package. But I don't have much experience with ts. It somethig like `nest` dto's – Levaya Pochta Apr 23 '21 at 00:32
  • "yes, I want to write own validation package." that's something you should mention in the question. You also need to show your attempt. Open ended "write my code for me" questions aren't welcome here, because this isn't a free code-writing service – Alexander Apr 23 '21 at 00:43

0 Answers0