Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Argument of type 'string' is not assignable to parameter of type 'never' how to fix it?

How to fix the Type issue in react typescript.

I am new to react-typescript, and I am fetching objects with string property from the server. And updating the state.

How to fix the error with type:

Argument of type 'string' is not assignable to parameter of type 'never'

formMethods and setValue coming from the react-hook-form

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]);

This is getUspsCityState function:

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);
    }
  });

ERROR enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda