mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Some API routes were updated in https://github.com/coder/coder/pull/401, which impacted the UX - the flow is currently broken when trying to navigate to a project:  This fixes all the routes so that the complete project -> create workspace -> workspace page flow works:  Because this had to touch a bunch of UI routes, I also opportunistically fixed #380 as part of this change. Fixes #380
18 lines
614 B
TypeScript
18 lines
614 B
TypeScript
/**
|
|
* unsafeSWRArgument
|
|
*
|
|
* Helper function for working with SWR / useSWR in the TypeScript world.
|
|
* TypeScript is helpful in enforcing type-safety, but SWR is designed to
|
|
* with the expectation that, if the argument is not available, an exception
|
|
* will be thrown.
|
|
*
|
|
* This just helps in abiding by those rules, explicitly, and lets us suppress
|
|
* the lint warning in a single place.
|
|
*/
|
|
export const unsafeSWRArgument = <T>(arg: T | null | undefined): T => {
|
|
if (typeof arg === "undefined" || arg === null) {
|
|
throw "SWR: Expected exception because the argument is not available"
|
|
}
|
|
return arg
|
|
}
|