microsoft / microsoft/TypeScript
language service suggestion for Declare property '...' in constructor argument
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
Search Terms
- typescript declare property in constructor
- typescript language service declare property in constructor
Suggestion
When a non-existing property x is accessed on this in a class method, one of the fixes that ts language service currently suggests, is:
Declare property x
Which adds property x to the class.
It would be nice to also have Declare property x in constructor arguments.
It can use private access modifier by default.
Use Cases
While it's generally useful, it becomes especially handy when developing applications with DI frameworks like Angular that use constructor injection to wire dependencies together.
Examples
-
Checklist
My suggestion meets these guidelines:
- 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. new expression-level syntax)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从现有的 TypeScript language-service 对“Declare property x”的建议开始,追踪其 code-fix 入口点及测试(如果存在)。添加所要求的替代方案:在构造函数参数中声明 x,并将 private 作为默认修饰符;然后在所描述的类方法场景中验证该建议及其生成的结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100