question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Register returns any, breaking typescript's type check

See original GitHub issue

Describe the bug The register function returns any, breaking typescript’s type check.

Code snippet

// MyComponent/index.ts
import { register } from 'react-native-bundle-splitter';

export default register({ loader: () => import('./MyComponent') });
// MyComponent/MyComponent.tsx
import React from 'react';
import { View } from 'react-native';

type Props = {
  isActive: boolean;
};

export default (_props: Props) => {
  return <View />;
};
// Screens/index.tsx
import React from 'react';
import MyComponent from '../MyComponent';

export default () => {
  // The following code should fail the type check
  return <MyComponent wrongProp1={[]} wrongProp2={false} />;
};

Repo for reproducing https://github.com/demedos/bundle-split-repro

To Reproduce Steps to reproduce the behavior:

  1. Add the bundle split to a component
  2. Import the component into another one
  3. Pass the wrong props

Expected behavior Typescript’s type check (yarn tsc) should throw an error

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Desktop OS: NA
  • Device: NA
  • OS: NA
  • JS engine: NA
  • Library version: 2.1.0

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kirillzyuskocommented, Feb 7, 2022
1reaction
demedoscommented, Jan 25, 2022

Sounds good, thank you 🙂 The only downside of this is that passing FC<Props> as a generic may be wrong, because even if the source component is a FC, optimized always returns a new pure component. Nonetheless, it should work without any problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Casting to :any breaks type check - Stack Overflow
I would expect some error message like Type any is not assignable to type string . I let a bug slip through to...
Read more >
Runtime type checking · Issue #1573 · microsoft/TypeScript
I request a runtime type checking system that perhaps looks something like this: function square(x: number!) { return x * x; } Where...
Read more >
Take control of unexpected data at runtime with TypeScript
Using TypeScript to stop unexpected data from breaking your app. In this article, we'll explore how to use TypeScript type definitions to ...
Read more >
TSConfig Reference - Docs on every TSConfig option
Ensures that any non-empty case inside a switch statement includes either break or return . This means you won't accidentally ship a case...
Read more >
A Complete Guide to Using TypeScript in Node.js - Better Stack
The TypeScript compiler is able to automatically detect the types of any library that's written in TypeScript (like date-fns ), so that it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found