ts-odd
ts-odd copied to clipboard
Eliminate impossible states on initialise
User feedback 💌
With the StrictNullCheck
enabled in Typescript, users are required to do:
case Scenario.AuthSucceeded:
case Scenario.Continuation:
if (state.fs != null) {
if (state.fs.appPath != null) {
const appPath = state.fs.appPath();
...
}
}
Ideally we would not need to do these "null" checks, but not sure how much we could eliminate these. Seeing that the presence of these things depends on the options given to initialise
. state.fs
can be undefined if given the loadFileSystem: false
option (which one may do to load the file system themselves in a web worker), and fs.appPath
can be undefined if the permissions.app
option was not set.
One option (not necessarily the right one) is only expose a FS handle if the app path is available, and hide all of the above detail. As a quick sketch:
fission.withApp("icidasset", "diffuse", app => {
// do stuff with App here
});
or even wrap it in a promise so you get the reject
:
const app = await fission.getApp({
creator: "icidasset",
appName: "diffuse"
}).catch(err => handleErr(err));
which may be good if it also will have to wait for the network
(That said, this is pretty seriously monadic in flavour, so it could just be that my brain is DEEP in Haskell land at present)
state.fs
can be undefined if given theloadFileSystem: false
I read this and was thinking there's a solution for this:
https://github.com/fission-suite/webnative/blob/fea00981c64307b336605da024fc1b5a5708f49a/src/index.ts#L102-L121
But I think the solution is quite ugly and IMHO I don't think it's worth it. There's probably a better way to structure this API, most likely one that uses typescript's capability of depending on the actual parameter's values more effectively.