microsoft / microsoft/TypeScript
Parameters required by default when generating modules from JavaScript files
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the handbook section on JavaScript function parameters and reproduce the example with the TypeScript 4.1.2x behavior described here. Investigate how JavaScript files are checked and how optional parameters are configured; done means the documented optional-by-default behavior or an explicit configuration choice is consistently reflected in the reported types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100