Skip to content

Use TypeScript declaration files alongside JavaScript #38732

@tqwewe

Description

@tqwewe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions