-1

I get this error when running tsc enter image description here

But when I open the file in VS Code, I don't get any error. Here's the code

    const validWorkAddresses = workAddresses.filter((item) => !!item)
    try {
      const response = await triggerCreateRoute({
        year,
        createRouteInput: {
          homeAddress,
          workAddresses: validWorkAddresses,
          selectedRoute,
          overrideRoundtripDistanceKm,
          suggestionId: routeData.suggestionId,
          routeId,
        },
      }).unwrap()
      setIsShowingEditDialog(false)
      handleRouteResponse(response, 'DUPLICATE')
    } catch (e) {}

workAddresses is of type DawaAddress | undefined)[] and updateRouteInput.workAddresses is of type DawaAddress[]

VS Code seems to understand that by running const validWorkAddresses = workAddresses.filter((item) => !!item) the list will not contain undefined elements.

Can I tweak tsc to get it?

1

1 Answer 1

0

You could certainly do the following:

workAddresses.filter((item): item is DawaAddress => !!item)

Why it is not happening automatically with your tsc I do not know.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.