Appearance
Twill extends TypeScript with Swift-inspired syntax. Add guards, defer, trailing closures and checked switch expressions; keep TypeScript's types and compile to ordinary JavaScript.
TypeScript types · No language runtime · Experimental 0.1
async function readOwned(acquire) {
const resource = await acquire();
defer {
await resource.close();
}
guard const name = await resource.read() else {
return 'Missing';
}
return name.toUpperCase();
}Native arrows, branches and framework APIs.
Inference, narrowing and checked union cases.
Keep TS/JS imports and your existing build.
Small changes to the code you read every day.
const user = findUser(id);
if (user == null) {
return 'Missing';
}
return user.name;guard const user = findUser(id) else {
return 'Missing';
}
return user.name;An explicit exit narrows the value for the rest of the scope. Nullish checks keep zero and false.
Read the semantics and tradeoffsWrite, check, format and debug in one working loop.
Use Twill where clearer control flow earns its place. Keep the rest of your project in TypeScript.