Typescript: Introducing `AS` and `ANY` keywords

Created on 18 Jun 2020  路  2Comments  路  Source: microsoft/TypeScript

Search Terms

AS ANY capitalize upper case

Suggestion

Introducing AS and ANY keywords instead of or in addition to as and any.

When using as or any, many TS programmers need to have their determination and overcome their inferior feeling to break type-safe code. AS and ANY can express their strong will more than as and any do.

Additionally, capitalized words attract notice so that they can be easily fixed at a later point. as and any have average looking. If they are something to avoid, they should have distinct looking. AS and ANY express that we should avoid to use them.

This feature should be configurable on tsconfig to avoid breaking existing codes.

Use Cases

AS and ANY can be used at any place where as and any are used.

Examples

  • let variable: ANY
  • req.headers AS Headers

Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [x] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of the expressions
  • [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x] This feature would agree with the rest of TypeScript's Design Goals.
Declined Suggestion

Most helpful comment

This doesn't really fit with our philosophy of how the language should work. Editors could use font ligatures or other display logic to render those keywords differently if that's desirable.

All 2 comments

And.. // TS-IGNORE ?

This doesn't really fit with our philosophy of how the language should work. Editors could use font ligatures or other display logic to render those keywords differently if that's desirable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartynasZilinskas picture MartynasZilinskas  路  3Comments

bgrieder picture bgrieder  路  3Comments

jbondc picture jbondc  路  3Comments

uber5001 picture uber5001  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments