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 support page #2710

Merged
merged 1 commit into from
Oct 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description:
eleventyNavigation:
key: Help
parent: Start
order: 6
order: 7
---

:::lead
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: TypeScript support
date: Last Modified
permalink: /docs/typescript-support/index.html
eleventyNavigation:
key: TypeScript support
parent: Start
order: 6
---

:::lead
How to add TypeScript support to your project.
:::

The type definitions for `react-native-web` are available on [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-native-web).

---

## Installation

Simply install the following dependency in your project.

```shell
npm install --save-dev @types/react-native-web
```

The package comes with the `react-native-web` declaration types, so you can use it normally in your project.

```ts
import { AppRegistry } from 'react-native-web';
```

---

## Using it in React Native projects

To extend the `react-native` types, you have to supply `react-native-web` as a member of the `types` compiler option in the `tsconfig.json` file.

```json
{
...
"compilerOptions": {
"types": ["react-native-web"]
}
}
```

Now you can use `react-native` components in your project with TS support to `react-native-web` props and styles :tada:

```jsx
import { View, ViewStyle } from 'react-native';

const style: ViewStyle = {
position: "fixed", // RN style properties are augmented with Web-only options e.g. 'fixed'
marginBlock: "auto", // All Web CSS style properties are also available to use
};

<View
href="https://necolas.github.io/react-native-web/" // RNW prop
style={style}
/>
```