You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since constructors have no return types. However, this is a perfectly valid use case for languages like TypeScript, as result<> return type are lowered into blob directly, using exceptions to propagate error-type values if they occur. Without it, APIs are forced to use alternative method names like blob::create(), which is not standard, and hurts readability/discoverability.
Thoughts? I wonder if it is possible to enable this use case..
Thanks for the report! This might be best discussed upstream since that's what governs the design of WIT itself rather than this repository, but in the meantime the main rationale for this is that many languages with native constructor support (e.g. JS and C++) can't support this which is why it's not supported. The alternative is a static function which returns the result, and that wouldn't get constructor treatment.
but in the meantime the main rationale for this is that many languages with native constructor support (e.g. JS and C++) can't support this which is why it's not supported.
I think that is orthogonal since neither JS jor C++ support result<> in normal functions either way. They emulate this via exceptions. My suggestion is to do the same for constructors, rather than special casing them.
Activity
alexcrichton commentedon Jan 8, 2025
Thanks for the report! This might be best discussed upstream since that's what governs the design of WIT itself rather than this repository, but in the meantime the main rationale for this is that many languages with native constructor support (e.g. JS and C++) can't support this which is why it's not supported. The alternative is a
staticfunction which returns theresult, and that wouldn't getconstructortreatment.OmarTawfik commentedon Jan 9, 2025
I will close and re-open upstream. Thanks!
I think that is orthogonal since neither JS jor C++ support
result<>in normal functions either way. They emulate this via exceptions. My suggestion is to do the same for constructors, rather than special casing them.alexcrichton commentedon Jan 9, 2025
Oh dear, sorry I realize I didn't fully read over your initial posting here which already explained everything I said. Sorry about that!
OmarTawfik commentedon Jan 9, 2025
No worries at all :) thanks for considering!