quick-lint-js

Find bugs in JavaScript programs.

E0283: TypeScript <Type> casts are not allowed in JSX mode

TypeScript supports two styles for type assertions: <Type>variable and variable as Type. It is a syntax error to use the former style in a .tsx file:

interface Payload { data: string; }
interface PayloadError { error: string; }

function useFetchPayload(uri, onResult) {
  useEffect(async () => {
    let data = await (await fetch(uri)).json();
    onResult(<Payload | PayloadError>data);
  }, [uri]);
}

To fix this error, use as instead:

interface Payload { data: string; }
interface PayloadError { error: string; }

function useFetchPayload(uri, onResult) {
  useEffect(async () => {
    let data = await (await fetch(uri)).json();
    onResult(data as Payload | PayloadError);
  }, [uri]);
}

Documentation for other errors