import { validate } from "superstruct-ts-transformer" ; type HttpBinGetResponse = { args : { [ key ] : any ; } ; headers : { [ key ] : string ; } ; origin : string ; url : string ; } ; fetch ( "https://httpbin.org/get" ) . then ( response => response . json ( ) ) . then ( json => validate < HttpBinGetResponse > ( json ) ) . then ( httpBinResponse => { const responseStr = JSON . stringify ( httpBinResponse , undefined , "  " ) ; document . body . innerHTML = `<div style="color:black;">${ responseStr }</div>` ; } ) . catch ( error => { const errorStr = error . message ; document . body . innerHTML = `<div style="color: red;">${ errorStr }</div>` ; } ) ;