Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript definition #6

Merged
merged 9 commits into from
Apr 6, 2020

Conversation

colinking
Copy link
Contributor

@colinking colinking commented Dec 19, 2019

This PR adds TS types to ink-link.

I based the typings on ink-text-link: https://github.com/vadimdemedes/ink-text-input

It also includes the fallback prop added in this PR: #5

@colinking colinking marked this pull request as ready for review December 19, 2019 19:16
@sindresorhus
Copy link
Owner

Thanks for creating a TypeScript definition. 🙌 Can you follow this styleguide?

Some examples:

@sindresorhus
Copy link
Owner

Friendly bump :)

@colinking colinking changed the title Add Typescript types Add TypeScript definition Apr 4, 2020
@colinking
Copy link
Contributor Author

Hey @sindresorhus! Finally got around to updating this to use the styleguide.

One thing: I'm not sure which React type to use on an instance of a React Component -- do you?

image

@sindresorhus
Copy link
Owner

One thing: I'm not sure which React type to use on an instance of a React Component -- do you?

I don't. Maybe look at some other React package with a index.d.ts file and see how they do it?

@colinking
Copy link
Contributor Author

I poked around on GitHub and found a number of folks using React + tsd, but none of them were checking the type of a React node: https://github.com/search?q=expectType+tsd+react&type=Code

From inspecting the createElement API, I tried expectType<FunctionComponentElement<Props>>(<Link/>) with no luck:

  index.test-d.tsx:6:0
  ✖  6:0  Parameter type FunctionComponentElement<Props> is not identical to argument type Element.
  ✖  7:0  Parameter type FunctionComponentElement<Props> is not identical to argument type Element.
  ✖  8:0  Parameter type FunctionComponentElement<Props> is not identical to argument type Element.

It seems like tsd is requesting we specifically type check against the React.Element type, which is not exported.

Give that, I just removed the expectType checks and replaced them with a simple function, since the type checks don't add a lot of value -- we already know it's valid JSX. The important thing here imo is to validate that the component properties are correct which tsd will do by compiling the declarations.

Does that seem good to you? :)

@sindresorhus
Copy link
Owner

Does that seem good to you? :)

👍

@sindresorhus sindresorhus merged commit 1dd2575 into sindresorhus:master Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants