Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow type annotations in .js files in preparation for Type Annotations proposal #59648

Open
6 tasks done
thesoftwarephilosopher opened this issue Aug 15, 2024 · 0 comments
Open
6 tasks done
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@thesoftwarephilosopher
Copy link

πŸ” Search Terms

allow js file extension

βœ… Viability Checklist

⭐ Suggestion

Add an option to allow removing the error "[some feature] can only be used in TypeScript files"

Previous discussion: #10939

The compiler option would allow consuming .js files as if they were .ts files, but with some differences (see below). All type-checking, type-stripping, and code emitting features would remain as-is.

πŸ“ƒ Motivating Example

The Type Annotations proposal is the definite future of JavaScript.

This feature would:

  • Enable incremental adoption of the Type Annotations proposal by users
  • Enable incremental support of Type Annotations in the TypeScript compiler
  • Possibly help push that proposal forward a little more quickly by increased usage
  • Spread word that this proposal exists by gaining compiler support in tsc and its release notes

It's true that the exact syntax isn't definite yet, and it will probably be at least somewhat different than current TypeScript syntax.

However, that's exactly why adding initial support for plain TypeScript would not interfere with its eventually sealed syntax.

In other words, the initial support would simply parse it as "typed-javascript" but the TypedJavaScript parser would currently be exactly the same as the TypeScript parser for the time being, and allow gradual differentiation.

It would also be a good opportunity to allow TypedJavaScript mode to disallow namespaces, enums, constructor fields, etc.

πŸ’» Use Cases

  1. What do you want to use this for?

Writing future-ready JavaScript.

  1. What shortcomings exist with current approaches?

It doesn't take into account the pending type annotation proposal.

  1. What workarounds are you using in the meantime?

I can almost get this working with some VS Code hacks, but then tsc complains as soon as I run it.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants