Skip to content

React Native 0.71 adds first-class support for TypeScript

updated

The React Native team has published a post describing how the 0.71 release invests in the TypeScript experience through three changes: the new app template is TypeScript by default, TypeScript declarations ship with React Native, and the documentation is TypeScript First.

TypeScript app template

From 0.71, creating a new app with the React Native CLI produces a TypeScript app by default:

npx react-native init My71App --version 0.71.0

New apps start from App.tsx instead of App.js, and the project comes with a tsconfig.json already set up.

Built-in declarations

0.71 is the first release with built-in TypeScript (TS) declarations. Previously, types came from @types/react-native in the DefinitelyTyped repository. According to the post, that package only covered stable releases, its releases lagged behind React Native, and updating it required manually checking public API changes. Co-locating the types with React Native source is intended to improve correctness and maintenance, and the team is working on tools to keep Flow and TS aligned.

The team plans to deprecate @types/react-native for versions 0.73 and onward. Versions of @types/react-native tracking 0.71 and 0.72 will be released and will match the types in React Native on those release branches. From 0.73, TS types will only be available from React Native.

Migration

  • App maintainers can remove @types/react-native from devDependencies after upgrading to React Native >= 0.71. If a library lists @types/react-native as a peerDependency and triggers warnings, the post suggests filing an issue or PR asking it to use optional peerDependencies.
  • Library maintainers targeting versions below 0.71 may keep a peerDependency on @types/react-native, marked as optional in peerDependenciesMeta.
  • Maintainers of declarations depending on @types/react-native should review the breaking changes introduced with 0.71.

Flow users

Flow users can still typecheck apps targeting 0.71+, but the template no longer includes Flow configuration or a .flowconfig. A .flowconfig remains in the React Native repository as a starting point, and the 0.70 template can be referenced for new Flow apps.

Reporting bugs

Bugs in TS declarations should be submitted as PRs to both the React Native and DefinitelyTyped repositories, or, for those who don't know how to fix them, reported as a GitHub issue in the React Native repository mentioning @lunaleaps.

Documentation

The docs now treat TypeScript as the default language. Code examples allow inline TypeScript, and over 170 interactive examples were updated to pass linting, formatting and type-checking in the new template. Where TypeScript and JavaScript versions differ, either can be viewed.

The post closes by thanking the community maintainers of @types/react-native since 2015, contributors including @acoates, @eps1lon, @kelset, @tido64, @Titozzz and @ZihanChen-MSFT, and the maintainers of react-native-template-typescript.

Source: reactnative.dev