microsoft / microsoft/TypeScript
Use TypeScript declaration files alongside JavaScript
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.9.3
Search Terms:
TypeScript along side JavaScript
Code
Button.jsx
const Button = ({ text, onClick }) => {
return <button onClick={onClick}>{text}</button>
}
Button.d.ts
interface Props {
text: string
onClick: () => void
}
declare const Button: (props: Props) => Element
Expected behavior:
TypeScript should apply the types described in Button.d.ts and use them on Button.jsx.
Actual behavior:
The prop types in Button.jsx are any and are ignoring the typed written in Button.d.ts.
Playground Link: https://codesandbox.io/s/loving-mclaren-dvefd?file=/src/button/Button.jsx
Related Issues: https://stackoverflow.com/questions/53074172/typescript-declaration-files-for-local-js-files
Other Info:
I made a stackoverflow question about this but it doesn't seem to be known there. https://stackoverflow.com/questions/61932377/use-typescript-declaration-files-alongside-javascript
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 with the Button.jsx and Button.d.ts example, then reproduce the behavior using the linked CodeSandbox and the reported TypeScript 3.9.3 version. Trace how declaration files are associated with JavaScript files and confirm the intended behavior with a focused compiler test; done means the declared props are applied instead of inferred as any, or the limitation is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100