microsoft / microsoft/TypeScript
Suggestion: Allow Types in JS Files
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
I have a large Angular2 project written in JavaScript, in which we use transform-flow-strip-types in order to allow Angular2 dependency injection to work from JavaScript.
This is currently an error in a JavaScript file compiled with tsc:
class MyClass {
prop:string; //err: 'types' can only be used in a .ts file
constructor(x: string) { //err: 'types' can only be used in a .ts file
}
someMethod():string { //err: 'types' can only be used in a .ts file
}
}
I would like an allowTypesInJsFiles compiler option which would allow us to compile JavaScript files which contain types. All of the above errors would be valid if the flag is set. This would allow us to use Angular2 DI from JavaScript files.
I have a branch with a simple implementation which I have verified to work.
Is this a change which could be accepted? If so I will add tests and sign the CLA.
I think it would be very useful for people migrating large JavaScript projects to TypeScript.
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 reviewing the proposed implementation in commit 57a69d880251088d550500dcb018fc4e53895916 and the examples in this issue. Determine how the compiler option should affect typed JavaScript, then add tests covering the shown declarations and confirm they compile when the option is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100