DEV Community

Pierre
Pierre

Posted on

is there to use types in different screens

Hi,
I declare the following type in my screen toto.tsx

type STA = {
response: number,
id: number,
method: string,
next: string | null,
fields: {
id_field: number,
field_name: string,
field_longname: string,
field_city: string,
field_lat: number,
field_lng: number
}[],
stations: {
id_field: number,
field_name: string,
id_station: number,
station_longname: string,
station_type_awe: string,
id_station_type: number,
station_type_name: string,
station_archive: number,
lat: number,
lng: number,
alt: number,
measures: {
datasets: {
data:{
value: number,
label: string,
date: string,
dataPointText: number
}[],
label: string,
showLine:boolean,
borderColor:string,
backgroundColor:string,
pointStyle:string,
fill:boolean,
borderWidth:number,
pointRadius:number,
type:string,
},
labels: {}[],
unit: string,
chartContainer: string,
id_sensor_type: number,
id_sensor:number,
sensor_type: string,
sensor_type_longname: string,
sensor_type_awe: string,
}[],
measures_found: number,
station_found: number,
latest_measure: string,
}[],
map_center:{
lat: number,
lng: number,
},
}

but I need it for the Screen titi.tsx, as well. I can copy/past it but if I need in a third Screen, it will be not easy to manage it if a change happen.

How can I create a file for that prupose, that I could import into the needed Screens?

Should I simply create a file in /constants/? But it be a .ts, a .tsx, a js?

That would ne great

Thanks

Top comments (0)