Slice model typescript

Hello,

I start to create a nuxt with slicemachine. I decided to use typescript on my project.

I'm wondering about the .json model of a slice. I have a select type with options. I will have to test these entries in my component.

My question

Is it possible to have a typescript model that builds and exports a json to allow me to create a class that reflects this json and to have an enum structure that contains my options? The objective is to reduce string duplication in tests and to have only one source of truth.

1 Like

Hello @maxime.hersand thanks for reaching out!

Could you give us some more details about your use case?
Where wold these typescript model and JSONs files be located in your project, and how do you imagine them being generated in Slicemachine?

This issue has been closed due to inactivity. Flag to reopen.

Hi @maxime.hersand ,

I'm not sure what you mean here, do you want to create a Typescript interface from the model.json file?

Thanks.

Hello,

Sorry I take no time to answer.

What I mean is for example I have a select name status with options :

  • agenda
  • preco
  • stock

To avoid creating an enum which will be a duplication of what is declare in custom_type, is there a way to match typescript enum or something to had something like

v-if="slice.primary.status === STATUS.agenda"

And avoid have to declare somewhere :

export enum STATUS {
   agenda: 'agenda';
   preco: 'preco';
   stock: 'stock';
}

My reflexion is if for some reason I want to add a status, automaticaly I could test STATUS.newOption

Being discussed here: