This fork contains a few modifications to Typescript to preview the try-expression-proposal syntax. It is not intended to be used in production.
To play around with it for yourself
- Create a new npm project folder using
npm init. npm installthe built tgz file from the releases page of this repository.- In VSCode, create a new typescript file and open it to enable the Typescript engine, then run the command "Typescript: Select Typescript Version" and select the version from your node_modules folder.
- Create a tsconfig.json file with
strictNullChecksenabled. - If you run
tscit will just pass the syntax through to the Javascript file.
The following code should be valid
const [error, data]: TryResult<1> = try 1; if (error) { const e: TryError = error; const r: undefined = data; } else { const e: undefined = error; const r: 1 = data; } // try at the beginning of an arrow function body const [error1, data1] = (() => try someExpression() ?? otherexpression() ? true : false)(); // regular assignment, terminated by comma, semicolon, or other statement. const [error2, data2] = try someExpression() ?? otherexpression() ? true : false; // used as an array value, terminated by comma or end of array const [[error3, data3]] = [try someExpression() ?? otherexpression() ? true : false]; // used as an object value, terminated by comma or end of object const { res: [error4, data4] } = { res: try someExpression() ?? otherexpression() ? true : false }
Changelog
0.2
- Added the try-expression-proposal syntax to the parser basically copying the yield syntax.
0.1
- Failed attempt that only partly worked.
TypeScript
TypeScript is a language for application-scale JavaScript. TypeScript adds optional types to JavaScript that support tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the playground, and stay up to date via our blog and Twitter account.
Find others who are using TypeScript at our community page.
Installing
For the latest stable version:
npm install -D typescript
For our nightly builds:
npm install -D typescript@next
Contribute
There are many ways to contribute to TypeScript.
- Submit bugs and help us verify fixes as they are checked in.
- Review the source code changes.
- Engage with other TypeScript users and developers on StackOverflow.
- Help each other in the TypeScript Community Discord.
- Join the #typescript discussion on Twitter.
- Contribute bug fixes.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Documentation
Roadmap
For details on our planned features and future direction, please refer to our roadmap.