p.....k konto usunięte 10.11.2020, 15:37:08 0 + Jak zasilić sprytnie interfejs w tsx RESTem tak by nie wypisywać każdego argumentu osobno?np.: export interface MyInterface {a: string;b: string;...z: string;}---const [myInterface, setMyInterface] = useState();getData().then((response) => {setMyInterface({a: response.a,b: repsonse.b,...z: response.z})})#javascript #typescript
trustME trustME 10.11.2020, 15:41:33 0 + @programista4k: [key: string]: string ? Nie wiem w czym problem, że response wrzucić w setMyInterface?
chapak chapak 10.11.2020, 15:42:43 2 + @programista4k: Jak masz taką samą strukture jak interfejs to mozesz po prostu to przekazać.const [myInterface, setMyInterface] = useState();getData().then((response: MyInterface)Pokaż całość
LepiejWcaleNizPozno LepiejWcaleNizPozno 10.11.2020, 16:08:25 2 + @programista4k: standardową praktyką w projektach typescriptowych na githubie jest dopisywanie anyconst interface = null : any
np.:
export interface MyInterface {
a: string;
b: string;
...
z: string;
}
---
const [myInterface, setMyInterface] = useState();
getData().then((response) => {
setMyInterface({
a: response.a,
b: repsonse.b,
...
z: response.z
})
})
#javascript #typescript
Jak masz taką samą strukture jak interfejs to mozesz po prostu to przekazać.
const [myInterface, setMyInterface] = useState();
getData().then((response: MyInterface)
const interface = null : any