microsoft / microsoft/TypeScript

Use TypeScript declaration files alongside JavaScript

Open
#38,732 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.