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

std: Provide types for React and ReactDOM #4376

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Mar 14, 2020

Fixes #4197

Introduces std/types which is designed to provide types for common libraries that are compatible with Deno.

Under strict mode, JSX is strongly typed. Without a JSX library being in scope of the compiler, the compiler is uncertain of what JSX is actually supported. At the same time, while React works under Deno, there are currently no available sources of React which supply compatible types, meaning that working with JSX under a TSX file does not work.

This PR provides types, based on DefinitelyTyped types, that work with Deno.

Once merged, they could be used like this:

// @deno-types="https://deno.land/std/types/react.d.ts"
import React from "https://cdn.pika.dev/_/react/v16";

const Component = () => (<div>Hello world!</div>);

This is still not quite ideal, because it would be great if the X-TypeScript-Types were set on the source and the compiler hint would no longer be required. @sholladay suggested that deno.land/x/ could host a redirect that also set the X-TypeScript-Types header. I also think @FredKSchott would be interested in this for Pika.

kitsonk added 2 commits March 15, 2020 07:12
Introduces `std/types` which is designed to provide types for common
libraries that are compatible with Deno.
They are adapted and modifying them to lint them doesn't make sense.
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit 9050d36 into denoland:master Mar 17, 2020
@irustm
Copy link

irustm commented Mar 24, 2020

Why do types of third-party libraries have to be in std?
And if I need support for one more rendering thing, do I have to send it to std?

@kitsonk
Copy link
Contributor Author

kitsonk commented Mar 24, 2020

@irustm it is a convenience, because of the popularity of React, especially in the Deno community working on server side rendering with React.

There are several type libraries at Definitely Typed (@types) that do not work with Deno because they don't have extensions on their imports. Compatible versions could be hosted anywhere, though. They don't have to be part of std.

Eventually, I would hope we would/could solve converting @types types on the fly and either directly providing @types compatible with Deno, or a community member providing them. I talked briefly to @FredKSchott about this a while back for pika.dev/cdn, but like a lot of things, there are a lot of priorities.

@FredKSchott
Copy link

Pika CDN serves @types/* for any packages that it can, if no type declarations are shipped with the package itself.

React I think is the ONE package that we don't, for dumb implementation reasons on my end. I'll add it to my roadmap to serve React & ReactDOM types as well now that that's a use-case that Deno is interested in.

caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
Introduces `std/types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
Introduces `types` which is designed to provide types for common
libraries that are compatible with Deno.
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.

v0.35.0 TSX file can't be compiled
4 participants