Upgrading to React Native 0.88: What Breaks in TypeScript
DEV Community

Upgrading to React Native 0.88: What Breaks in TypeScript

React Native 0.88 shipped with no user-facing breaking changes. That is true if you're coming from 0.87.

If you're on 0.86, which includes anyone moving from Expo SDK 57 to SDK 58, you also take everything in 0.87. That release made the Strict TypeScript API the default.

I compiled one small file of common old-style patterns against each setup:

Setup Type errors
React Native 0.86 0
React Native 0.88.1 (Strict API, default) 14
React Native 0.88.1 (legacy opt-out) 5

Tested with @react-native/typescript-config and TypeScript 6.0.3 for 0.86, and 7.0.2 for 0.88.1. The fixed version below passes on both 6.0.3 and 7.0.2.

The "before" file

This type-checks cleanly on 0.86:

import { useRef } from 'react';
import {
  AppStateStatic,
  InteractionManager,
  Modal,
  ScrollView,
  StatusBar,
  Text,
  TextInput,
  Touchable,
  useColorScheme,
  View,
  ViewProperties,
  NativeMethods,
} from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';

export function Screen(props: ViewProperties) {
  const viewRef = useRef<View>(null);
  const inputRef = useRef<TextInput>(null);
  const scheme: 'light' | 'dark' | 'unspecified' | null | undefined = useColorScheme();
  InteractionManager.runAfterInteractions(() => inputRef.current?.focus());
  StatusBar.setBackgroundColor('#000');
  return (
    <View {...props} ref={viewRef}>
      <StatusBar backgroundColor="#000" translucent />
      <Modal animated />
      <ScrollView keyboardShouldPersistTaps={true} />
      <Text lineBreakMode="tail">{scheme}</Text>
      <TextInput ref={inputRef} />
    </View>
  );
}

What changed, and how to fix it

1. Deep imports are type errors

TS2307: Cannot find module 'react-native/Libraries/Utilities/codegenNativeComponent' or its corresponding type declarations.

The public API is now only what react-native exports at its root.

// Before
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';

// After
import { CodegenTypes, codegenNativeComponent } from 'react-native';
type Count = CodegenTypes.Int32;

If you truly need an internal module (in a test, say), you have to acknowledge it:

// @ts-expect-error - React Native internal, untyped under the Strict API
import NativeAppState from 'react-native/Libraries/AppState/NativeAppState';

jest.mock() paths don't need to change.

2. useRef<View> no longer works

TS2339: Property 'focus' does not exist on type 'TextInputType'.

TS2322: Type 'RefObject<TextInputType | null>' is not assignable to type 'Ref<_TextInputInstance> | undefined'.

Built-in components are now function types, so the component name is no longer the instance type. Use the *Instance types:

// Before
const viewRef = useRef<View>(null);
const inputRef = useRef<TextInput>(null);

// After
const viewRef = useRef<ViewInstance>(null);
const inputRef = useRef<TextInputInstance>(null);

React.ComponentRef<typeof View> also works.

3. Old type names are gone

Removed Use instead
ViewProperties and other *Properties ViewProps and other *Props
AppStateStatic and other *Static The value's own name, e.g. AppState
NativeMethods HostInstance
Touchable (undocumented root export) ViewProps, if you extended it as a type

4. InteractionManager is removed

TS2305: Module '"react-native"' has no exported member 'InteractionManager'.

The suggested replacement is requestIdleCallback:

// Before
InteractionManager.runAfterInteractions(() => inputRef.current?.focus());

// After
useEffect(() => {
  const handle = requestIdleCallback(() => inputRef.current?.focus(), { timeout: 500 });
  return () => cancelIdleCallback(handle);
}, []);

This is not a drop-in swap. runAfterInteractions waited for interactions and animations to finish. requestIdleCallback waits for idle time on the JS thread, which says nothing about a native-driven transition. If you were waiting for a screen transition, use your navigator's transition-end event and test on a real device.

5. Props and methods that were removed

Removed What to do
StatusBar backgroundColor, translucent, networkActivityIndicatorVisible and their setters Draw your own background behind the status bar using safe area insets
Modal animated animationType="slide", "fade" or "none"
keyboardShouldPersistTaps={true} "always" (and "never" instead of false)
Text lineBreakMode ellipsizeMode

6. useColorScheme() returns a different type

It now returns ColorSchemeName | null and no longer returns 'unspecified'.

const scheme: ColorSchemeName = useColorScheme() ?? 'light';

My test file didn't error on this because its annotation was wide enough to accept the new type. Search for comparisons with 'unspecified' yourself.

The "after" file

This compiles with zero errors on 0.88.1:

import { useEffect, useRef } from 'react';
import {
  CodegenTypes,
  codegenNativeComponent,
  ColorSchemeName,
  Modal,
  ScrollView,
  StatusBar,
  Text,
  TextInput,
  TextInputInstance,
  useColorScheme,
  View,
  ViewInstance,
  ViewProps,
} from 'react-native';

interface NativeProps extends ViewProps {
  count?: CodegenTypes.Int32;
}

export const Counter = codegenNativeComponent<NativeProps>('RNCounterView');

export function Screen(props: ViewProps) {
  const viewRef = useRef<ViewInstance>(null);
  const inputRef = useRef<TextInputInstance>(null);
  const scheme: ColorSchemeName = useColorScheme() ?? 'light';
  useEffect(() => {
    const handle = requestIdleCallback(() => inputRef.current?.focus(), { timeout: 500 });
    return () => cancelIdleCallback(handle);
  }, []);
  return (
    <View {...props} ref={viewRef}>
      <StatusBar barStyle={scheme === 'dark' ? 'light-content' : 'dark-content'} />
      <Modal animationType="slide" />
      <ScrollView keyboardShouldPersistTaps="always" />
      <Text ellipsizeMode="tail">{scheme}</Text>
      <TextInput ref={inputRef} />
    </View>
  );
}

Find affected code before you upgrade

grep -rnE "react-native/Libraries/|InteractionManager|useRef<(View|TextInput|ScrollView|FlatList)\b|(AppState|Linking|Platform|Keyboard|Alert)Static|ViewProperties|NativeMethods|setBackgroundColor|unspecified" src

It won't catch everything (JSX props especially), so run npx tsc --noEmit after upgrading.

Need to ship now? The opt-out

{
  "extends": "@react-native/typescript-config",
  "compilerOptions": {
    "customConditions": ["react-native", "react-native-legacy-deep-imports"]
  }
}

Two things to know:

  • It doesn't fix removals. My file still had 5 errors: InteractionManager, the StatusBar setter and props, Modal animated and the boolean keyboardShouldPersistTaps.
  • It's temporary. The 0.87 post said the legacy types were planned for removal after 0.88, while Expo's SDK 58 notes say after 0.89. The 0.89.0-rc.5 package I checked still includes them, but I wouldn't plan around that.

Errors coming from dependencies?

Keep skipLibCheck: true. The React Native config already enables it. Update the library first. For example, the migration guide lists react-native-safe-area-context 5.8.1+ as a fixed version.

Library authors: if you ship raw .ts source, it gets type-checked inside your users' apps. Remove deep imports, or ship compiled output with .d.ts files.

Upgrade checklist

  1. Update dependencies.
  2. Run the search above.
  3. Fix removed APIs first, since the opt-out can't help with them.
  4. Move deep imports to root imports.
  5. Update ref types.
  6. Run tsc, then test focus, status bar and transition behaviour on devices.

Also on 0.88: react-native/Libraries/Core/InitializeCore is deprecated, so switch to import 'react-native/setup-env';.

What broke in your upgrade that isn't listed here? Tell me in the comments.

Found this helpful? Drop a ❤️ on the article!

Questions or suggestions? Drop them in the comments below. Feel free to reach out:

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.