Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!