Cómo solucionar el problema de Tipo en React TypeScript.
Soy nuevo en react-typescript y estoy obteniendo objetos con propiedad de cadena del servidor. Y actualizando el estado.
Cómo corregir el error con el tipo:
Argument of type 'string' is not assignable to parameter of type 'never'formMethods y setValue provenientes del formulario de gancho de reacción
useEffect(() => { if (address.postalCode?.length === 5) { const getCityState = async () => { const response = await getUspsCityState(address.postalCode); if (response) { const { city, state } = response; // HERE I AM getting error: // Argument of type 'string' is not assignable to parameter of type 'never' formMethods.setValue('address.city', city, { shouldDirty: true, shouldValidate: true, }); } }; getCityState(); } }, [formMethods, watchPostalCode]);Esta es la función getUspsCityState:
export const getUspsCityState = ( zipcode: string, ): Promise<UspsCityState | null> => new Promise((resolve, reject) => { try { const xmlString = `<?xml version="1.0"?><CityStateLookupRequest USERID="${USPS_USER_ID}"><ZipCode><Zip5>${zipcode}</Zip5></ZipCode></CityStateLookupRequest>`; const api = 'CityStateLookup'; return fetch(`${USPS_SERVER}?API=${api}&XML=${xmlString}`, { method: 'GET', }) .then(response => response.text()) .then(xmlResponse => { const state = xmlResponse.match(/<State>([^<]+)<\/State>/i); const city = xmlResponse.match(/<City>([^<]+)<\/City>/i); if (state && state[1] && city && city[1]) { return resolve({ state: state[1], city: city[1] }); } return resolve(null); }); } catch (e) { return reject(e); } });