overloaded the open function for convenient type inference#5619
overloaded the open function for convenient type inference#5619lucasfernog merged 5 commits intotauri-apps:nextfrom Fractal-Tess:open-overload
Conversation
combine jsdoc return types Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
Fixed an error, where typescript would yell when a nonlitteral boolean was provided
|
Duplicate of #5128. I'm not sure if this is a breaking change (like if you're using |
|
The duplicate is my bad, forgot that 5128 exists. i don't think this is a breaking change btw. I can't think of any scenario and nothing occurred in my testing (i tried to explicitly test this which is also where we noticed the issue that was fixed in the last commit). But yeah i see why you'd prefer to be safe here, with JS/TS being what it is there are probably 10 edge cases here i could never even think of 😂 |
|
@lucasfernog I think function overload is more readable than conditional types, maybe I should close my pr #5128 ? Further, should the options be restricted entirely to the OpenDialogOptions type? My exposure to TS is too short to judge what the best practices are. |
|
Hey there, So a couple of things to get out of the way. First of all, this is all my bad for not communicating with the maintainers on the topic as I only ever talked a little bit to Amr, but it was really short we didn't exactly exchange any feedback. However, for the foreseeable future, I will try to open an issue and have an open discussion with the developers before doing random prs. Credit is where credit is due, and I just have to metion Fabian, who also helped me greatly with this and even found a mistake I had originally left out in the pr, where a non-literal boolean type would give off errors. All that being said, my stupidity took the better of me and I took @jianxingxuejian 's suggestion on the overload and shipped the changes in a new commit without re-testing the types. Testing it after the changes, the type for a non-literal boolean value is I'll revert the last commit as to how it originally was, and I'm still open to new ideas on how to improve the overload, as I myself am not all that experienced with typescript. Once again, sorry for this! On a side note, this is what we want: const s1 = await open() // string | null
const s2 = await open({}) // string | null
const s3 = await open({ multiple: true }) // string[] | null
const s4 = await open({ multiple: false }) // string | null
const s5 = await open({ multiple: Boolean(1) }) // string | string[] | null |
|
Yeah @jianxingxuejian let's go with this approach. |
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Checklist
fix: remove a typo, closes #___, #___)Other information
This pr introduces a simple function overload to provide convenient types based on input options.
I've refactored the original examples, cutting one of them outright and reducing the first one.
However, if you feel like this is not enough, please request a change with some instructions on how to make it better.