🔍 Search Terms
✅ Viability Checklist
⭐ Suggestion
Current syntax is an error in TS. Support a syntax which is interpreted as a throw type annotation in ErrorScript but ignored in TS. For example:
// Definition for TS, ignored by ErrorScript
namespace ErrorScript {
type Result<T, E> = T // This type is valid only as a return type
type Promise<T, E> = Promise<T>
}
function maybeGetNumber(): ErrorScript.Result<number, DOMException> {
const n = Math.random()
if (n < 0.5) throw new DOMException("Too low", "RandomError")
return n
}
async function maybeGetNumberLater(): ErrorScript.Promise<number, DOMException> {
const n = Math.random()
if (n < 0.5) throw new DOMException("Too low", "RandomError")
return n
}
Additionally, for JS with JSDoc, a @throws tag could be used:
/**
* @returns {number}
* @throws {DOMException}
*/
function maybeGetNumber() {
const n = Math.random()
if (n < 0.5) throw new DOMException("Too low", "RandomError")
return n
}
Also it would be worth adding a JS mode to the playground so the JSDoc support can be tested too.
📃 Motivating Example
💻 Use Cases
Easier migration. Not everybody has to switch at once.
🔍 Search Terms
✅ Viability Checklist
⭐ Suggestion
Current syntax is an error in TS. Support a syntax which is interpreted as a throw type annotation in ErrorScript but ignored in TS. For example:
Additionally, for JS with JSDoc, a
@throwstag could be used:Also it would be worth adding a JS mode to the playground so the JSDoc support can be tested too.
📃 Motivating Example
💻 Use Cases
Easier migration. Not everybody has to switch at once.