Allow type annotations in .js files in preparation for Type Annotations proposal
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, typescript
- 领域
- compilers
调研方向
先阅读 #10939 中之前的讨论以及链接的 TC39 Type Annotations 提案。然后检查 TypeScript 编译器目前对 .js 文件中仅限 TypeScript 语法的限制,并确定该选项的范围,包括哪些构造仍然不允许使用。完成的标准是:有一个文档化的编译器选项支持预期的类型化 JavaScript 解析,同时不改变生成的运行时行为。
由索引模型根据 Issue 内容生成。
描述
🔍 Search Terms
allow js file extension
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ 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
- What do you want to use this for?
Writing future-ready JavaScript.
- What shortcomings exist with current approaches?
It doesn't take into account the pending type annotation proposal.
- 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.
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 106
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
microsoft/TypeScript#64322 · 2 条评论 · 1 个 reaction · 已指派 2 人 ·
-
Possible Improvement
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64278 · 1 条评论 · 1 个 reaction ·
-
Docs
难度 2/5 1-3 小时 新手友好度 70/100
microsoft/TypeScript#64118 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
microsoft/TypeScript#64094 ·
-
Docs
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#63959 · 5 条评论 ·
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
Type/Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenNSW/nsw-srilanka#497 ·
-
难度 1/5 1 小时以内 新手友好度 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
难度 2/5 1-3 小时 新手友好度 88/100
kubernetes-sigs/prow#953 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 88/100
caddyserver/caddy#8046 ·