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

Refactor std/types #4713

Merged
merged 6 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions std/types/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
# std/types

Contains types for popular external packages that are compatible with Deno.
Contains type definitions for popular external packages that are compatible with
Deno.

Because Deno only resolves fully qualified file names, type definitions that
import other type definitions might not work with Deno. Also, when some type
definition supply some global interfaces, they can conflict with Deno. The types
located here have been validated to work with Deno.

The types that are currently available:

- `react.d.ts` - For React 16. Sources known to work well for Deno:
- Pika CDN: `https://cdn.pika.dev/_/react/v16`
- JSPM: `https://dev.jspm.io/react@16`
- `react-dom.d.ts` - For ReactDOM 16. Sources known to work well for Deno:
- Pika CDN: `https://cdn.pika.dev/_/react-dom/v16`
- JSPM: `https://dev.jspm.io/react-dom@16`

There are several ways these type definitions can be referenced. Likely the
"best" way is that the CDN provider provides a header of `X-TypeScript-Types`
which points to the type definitions. We are working to have this available, but
currently you would need to use the compiler hint of `@deno-types`. For example
to import React:

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

or

```typescript
// @deno-types="https://deno.land/std/types/react/@16.13.1/react.d.ts"
import React from "https://dev.jspm.io/react@16.13.1";
```

#### Notes:

JSPM transformation of most libraries export everything through the default
namespace, so most of the time it might not be suited to work along with this
definition library.
15 changes: 15 additions & 0 deletions std/types/prop-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Types for Facebook's Prop-Types library.

[![npm version](https://img.shields.io/npm/v/prop-types.svg?style=flat)](https://www.npmjs.com/package/prop-types)

You can use prop-types to document the intended types of properties passed to
functions and classes. This library is intended for his use alongside Facebook's
React library, but can be used freely for runtime type checking outside of the
React environment.

### Usage Examples

```typescript
// @deno-types="https://deno.land/std/types/prop-types/v15.7.2/prop-types.d.ts"
import PropTypes from "https://cdn.pika.dev/prop-types@15.7.2";
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// These types are adapted from
// https://github.com/DefinitelyTyped/DefinitelyTyped to work under Deno.
//
// Type definitions for prop-types 15.7
// Project: https://github.com/reactjs/prop-types, https://facebook.github.io/react
// Definitions by: DovydasNavickas <https://github.com/DovydasNavickas>
// Ferdy Budhidharma <https://github.com/ferdaber>
Expand Down
13 changes: 13 additions & 0 deletions std/types/react-dom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Types for Facebook's React DOM library.

[![npm version](https://img.shields.io/npm/v/react-dom.svg?style=flat)](https://www.npmjs.com/package/react-dom)

This package serves as the entry point to the DOM and server renderers for
Facebook's React library.

### Usage Examples

```typescript
// @deno-types="https://deno.land/std/types/react-dom/v16.13.1/react-dom.d.ts"
import ReactDOM from "https://cdn.pika.dev/@pika/react-dom@v16.13.1";
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// These types are adapted from
// https://github.com/DefinitelyTyped/DefinitelyTyped to work under Deno.
//
// Type definitions for React (react-dom) 16.9
// Project: http://facebook.github.io/react/
// Definitions by: Asana <https://asana.com>
// AssureSign <http://www.assuresign.com>
Expand Down Expand Up @@ -31,7 +30,7 @@ import {
DOMElement,
ReactNode,
ReactPortal,
} from "./react.d.ts";
} from "../../react/v16.13.1/react.d.ts";

export function findDOMNode(
instance: ReactInstance | null | undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

// @deno-types="../react.d.ts"
// @deno-types="../../../react/v16.13.1/react.d.ts"
import React from "./react_mock.js";
// @deno-types="../react-dom.d.ts"
import ReactDOM from "./react-dom_mock.js";

import { assertEquals } from "../../testing/asserts.ts";
import { assertEquals } from "../../../../testing/asserts.ts";

const { test } = Deno;

Expand Down
12 changes: 12 additions & 0 deletions std/types/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Types for Facebook's React library.

[![npm version](https://img.shields.io/npm/v/react.svg?style=flat)](https://www.npmjs.com/package/react)

React is a JavaScript library for building user interfaces.

### Usage Examples

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