microsoft / microsoft/TypeScript

Parameters required by default when generating modules from JavaScript files

未关闭
#41,745 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

TypeScript Version: 4.1.2x

Search Terms:
transpile javascript optional parameters

Code

export default function example (hello, optionalParam={}) {
  console.log(hello);
}
export default function example(hello: any, optionalParam?: object): void;

The first parameter is now required. While there is syntax to make parameters optional as shown above, shouldn't all javascript parameters be optional unless specified by a JSDoc?

Ideally there would be some configuration for this to allow a "optional by default".

Expected behavior:
https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#function-parameters-are-optional-by-default

Actual behavior:
Parameters are not optional by default.

Playground Link:

Related Issues:

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 handbook 中关于 JavaScript 函数参数的章节,并使用此处描述的 TypeScript 4.1.2x 行为重现该示例。调查如何检查 JavaScript 文件以及如何配置可选参数;当文档所述的默认可选行为或明确的配置选择能够一致地反映在报告的类型中时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。