This fork contains a few modifications to Typescript to preview the try-expression-proposal syntax. It is not intended to be used in production.
- Create a new npm project folder using
npm init
. npm install
the 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
strictNullChecks
enabled. - If you run
tsc
it will just pass the syntax through to the Javascript file.
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 }
- Added the try-expression-proposal syntax to the parser basically copying the yield syntax.
- Failed attempt that only partly worked.
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.
For the latest stable version:
npm install -D typescript
For our nightly builds:
npm install -D typescript@next
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.
For details on our planned features and future direction, please refer to our roadmap.