We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given this sample interface:
declare let fetchState: | { status: "loading" } | { status: "success"; data: string } | { status: "error" };
We could have switch-based braching:
switch
export default function MyComponent() { return ( <div> {(() => { switch (fetchState.status) { case "loading": return <p>Loading</p>; case "success": return <p>{fetchState.data}</p>; case "error": return <p>Oops</p>; } })()} </div> ); }
In order to be able to replace this snippet with our library, ie.:
export default function MyComponent() { return ( <Match value={fetchState}> <With status="loading"> <p>Loading</p> </With> <With status="success"> <p>{fetchState.data}</p> </With> <With status="error"> <p>Oops</p> </With> <Otherwise>Fallback</Otherwise> </Match> ); }
we'd need to ensure that when status is success, data exists. Instead, an error is thrown:
status
success
data
Property 'data' does not exist on type 'FetchState'. Property 'data' does not exist on type '{ status: "loading"; }'.ts(2339)
Probably, this should be addressed with some narrowing strategy (like type-predicates).
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
Given this sample interface:
We could have
switch
-based braching:In order to be able to replace this snippet with our library, ie.:
we'd need to ensure that when
status
issuccess
,data
exists. Instead, an error is thrown:Probably, this should be addressed with some narrowing strategy (like type-predicates).
Resources
The text was updated successfully, but these errors were encountered: