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

fix: enable strict mode for TS types #1466

Merged
merged 2 commits into from
Oct 29, 2024
Merged

Conversation

crutchcorn
Copy link
Contributor

Please verify the following:

  • yarn build-and-test:local passes
  • I have added tests for any new features, if relevant
  • README.md (or relevant documentation) has been updated with your changes

Describe your PR

This PR enables strict mode for the reactotron-core-client codebase to fix issues documented here:

#1430

@markwilcox
Copy link

Is there anything that needs to be done to move forward with this PR?

I'm trying to upgrade our large app to RN 0.74 and that uses TypeScript 5, at which point there's no way out of type checking imported .ts dependencies.

Because reactotron-react-native is importing reactotron-core-client from src .ts files, rather than compiled .js I cannot find a way to disable these checks (require hack in the linked issue does not work for our setup).

I'd be happy to help if we could get a version released that works with latest RN versions, given Flipper is removed in those versions Reactotron is more needed than ever. 😄

Copy link

@bruno-fialho bruno-fialho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also problems in:

  • "src/stopwatch.ts":
    • typeof window !== "undefined" && => Cannot find name 'window'.
    • performanceNow(started)[1] => Element implicitly has an 'any' type because expression of type '1' can't be used to index type 'Number'.
  • "src/validate.ts"
    • typeof host === "string" && host && host !== "" => Type 'string | boolean' is not assignable to type 'boolean'.
    • !isHostValid(host) => Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'.
    • !isPortValid(port) => Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'.
    • !onCommandValid(onCommand) => Argument of type '((command: any) => void) | undefined' is not assignable to parameter of type '(cmd: string) => any'. Type 'undefined' is not assignable to type '(cmd: string) => any'.

@@ -60,7 +60,7 @@ function serialize(source, proxyHack = false) {
* @param {*} value - The value to replace.
*/
function serializer(replacer) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing replacer type

@@ -352,7 +355,7 @@ export class ReactotronImpl implements ReactotronCore {
}

// this is ws style from require('ws') on node js
if ("on" in socket && socket.on) {
if ("on" in socket && socket.on!) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing evt type in line 370

@tabbathacrouch
Copy link

tabbathacrouch commented Oct 15, 2024

Any movement on this PR? I'm seeing these TS errors 👀 @bruno-fialho @marcusnunes89

node_modules/reactotron-core-client/src/plugins/benchmark.ts:15:18 - error TS2345: Argument of type '{ title: string; time: number; delta: number; }' is not assignable to parameter of type 'never'.

15       steps.push({ title: stepTitle, time: nextTime, delta: nextTime - previousTime })
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/plugins/benchmark.ts:17:16 - error TS2345: Argument of type '{ title: string; time: number; delta: number; }' is not assignable to parameter of type 'never'.

17     steps.push({ title, time: 0, delta: 0 })
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:104:55 - error TS2344: Type 'CustomCommandArg[] | undefined' does not satisfy the constraint 'CustomCommandArg[]'.
  Type 'undefined' is not assignable to type 'CustomCommandArg[]'.

104   onCustomCommand: <Args extends CustomCommandArg[] = CustomCommand["args"]>(
                                                          ~~~~~~~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:166:3 - error TS2416: Property 'options' in type 'ReactotronImpl' is not assignable to the same property in base type 'ReactotronCore'.
  Type 'ClientOptions<ReactotronCore>' is not assignable to type 'ClientOptions<this>'.
    Type 'this' is not assignable to type 'ReactotronCore'.
      Type 'ReactotronImpl' is not assignable to type 'ReactotronCore'.
        Types of property 'plugins' are incompatible.
          Type 'Plugin<this>[]' is not assignable to type 'Plugin<ReactotronCore>[]'.
            Type 'Plugin<this>' is not assignable to type 'Plugin<ReactotronCore>'.
              Type 'ReactotronCore' is not assignable to type 'this'.
                'this' could be instantiated with an arbitrary type which could be unrelated to 'ReactotronCore'.

166   options: ClientOptions<ReactotronCore>
      ~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:166:3 - error TS2564: Property 'options' has no initializer and is not definitely assigned in the constructor.

166   options: ClientOptions<ReactotronCore>
      ~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:224:9 - error TS2322: Type 'null' is not assignable to type '((path: string) => WebSocket) | ((path: string) => NodeWebSocket) | undefined'.

224         createSocket: null,
            ~~~~~~~~~~~~

  node_modules/reactotron-core-client/src/client-options.ts:16:3
    16   createSocket?: ((path: string) => BrowserWebSocket) | ((path: string) => NodeWebSocket)
         ~~~~~~~~~~~~
    The expected type comes from property 'createSocket' which is declared here on type 'ClientOptions<ReactotronCore>'

node_modules/reactotron-core-client/src/reactotron-core-client.ts:243:52 - error TS2345: Argument of type 'PluginCreator<ReactotronCore>' is not assignable to parameter of type 'PluginCreator<this>'.
  Type 'this' is not assignable to type 'ReactotronCore'.
    Type 'ReactotronImpl' is not assignable to type 'ReactotronCore'.
      Types of property 'plugins' are incompatible.
        Type 'Plugin<this>[]' is not assignable to type 'Plugin<ReactotronCore>[]'.
          Type 'Plugin<this>' is not assignable to type 'Plugin<ReactotronCore>'.
            Type 'ReactotronCore' is not assignable to type 'this'.
              'this' could be instantiated with an arbitrary type which could be unrelated to 'ReactotronCore'.

243       this.options.plugins.forEach((p) => this.use(p))
                                                       ~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:246:58 - error TS2344: Type 'PluginCreator<this>[] | undefined' does not satisfy the constraint 'PluginCreator<this>[]'.
  Type 'undefined' is not assignable to type 'PluginCreator<this>[]'.

246     return this as this & InferFeaturesFromPlugins<this, ClientOptions<this>["plugins"]>
                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:273:20 - error TS2722: Cannot invoke an object which is possibly 'undefined'.

273     const socket = createSocket(`${protocol}://${host}:${port}`)
                       ~~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:273:20 - error TS18048: 'createSocket' is possibly 'undefined'.

273     const socket = createSocket(`${protocol}://${host}:${port}`)
                       ~~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:285:26 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

285       getClientIdPromise(name).then((clientId) => {
                             ~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:464:33 - error TS18048: 'plugin.features' is possibly 'undefined'.

464         const featureFunction = plugin.features[key]
                                    ~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:503:7 - error TS2322: Type '(() => void) | undefined' is not assignable to type '() => void'.
  Type 'undefined' is not assignable to type '() => void'.

503       handler = optHandler
          ~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:508:7 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

508       title = config.title
          ~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:509:7 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

509       description = config.description
          ~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:510:7 - error TS2322: Type 'CustomCommandArg[] | undefined' is not assignable to type 'CustomCommandArg[]'.
  Type 'undefined' is not assignable to type 'CustomCommandArg[]'.

510       args = config.args
          ~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:537:9 - error TS2454: Variable 'args' is used before being assigned.

537     if (args) {
            ~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:545:30 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.

545         if (argNames.indexOf(arg.name) > -1) {
                                 ~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:551:23 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.

551         argNames.push(arg.name)
                          ~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:560:7 - error TS2454: Variable 'title' is used before being assigned.

560       title,
          ~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:561:7 - error TS2454: Variable 'description' is used before being assigned.

561       description,
          ~~~~~~~~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:562:7 - error TS2454: Variable 'args' is used before being assigned.

562       args,
          ~~~~

node_modules/reactotron-core-client/src/reactotron-core-client.ts:595:27 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'ClientOptions<ReactotronImpl>'.

595   return client.configure(options as unknown) as unknown as Client
                              ~~~~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/serialize.ts:105:39 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

105         const thisPos = stack.indexOf(this)
                                          ~~~~

node_modules/reactotron-core-client/src/serialize.ts:106:59 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

106         ~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
                                                              ~~~~

node_modules/reactotron-core-client/src/serialize.ts:107:51 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

107         ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
                                                      ~~~

node_modules/reactotron-core-client/src/serialize.ts:107:68 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

107         ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
                                                                       ~~~

node_modules/reactotron-core-client/src/serialize.ts:108:28 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

108         if (~stack.indexOf(value)) value = CIRCULAR
                               ~~~~~

node_modules/reactotron-core-client/src/serialize.ts:110:20 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

110         stack.push(value)
                       ~~~~~

node_modules/reactotron-core-client/src/validate.ts:8:48 - error TS2322: Type 'string | boolean' is not assignable to type 'boolean'.
  Type 'string' is not assignable to type 'boolean'.

8 const isHostValid = (host: string): boolean => typeof host === "string" && host && host !== ""
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/reactotron-core-client/src/validate.ts:24:20 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

24   if (!isHostValid(host)) {
                      ~~~~

node_modules/reactotron-core-client/src/validate.ts:28:20 - error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
  Type 'undefined' is not assignable to type 'number'.

28   if (!isPortValid(port)) {
                      ~~~~

node_modules/reactotron-core-client/src/validate.ts:32:23 - error TS2345: Argument of type '((command: any) => void) | undefined' is not assignable to parameter of type '(cmd: string) => any'.
  Type 'undefined' is not assignable to type '(cmd: string) => any'.

32   if (!onCommandValid(onCommand)) {
                         ~~~~~~~~~


Found 33 errors in 4 files.

Errors  Files
     2  node_modules/reactotron-core-client/src/plugins/benchmark.ts:15
    21  node_modules/reactotron-core-client/src/reactotron-core-client.ts:104
     6  node_modules/reactotron-core-client/src/serialize.ts:105
     4  node_modules/reactotron-core-client/src/validate.ts:8
 

@tabbathacrouch
Copy link

ready to merge? 👀 🚀 @marcusnunes89

@marcusnunes89
Copy link

@tabbathacrouch I don't have permission to merge, I'm just one of those who want this fixed so I can use it :P

@joshuayoes
Copy link
Contributor

Thank you for this addition! Sorry this sat for so long. Our open source labor at Infinite Red relies on contributions from our team members during downtime between client projects and donations of our free time, so sometimes painful issues like this fall through the cracks.

We needed to do a little more work to get our build_docs Cl job working to accept contributions from the community, but we've got that sorted out now, which will make community contributions like this easier for us to accept in the future.

@joshuayoes joshuayoes merged commit fd8cf47 into infinitered:master Oct 29, 2024
2 checks passed
@jahirfiquitiva
Copy link

@joshuayoes

Is there a way to use reactotron-core-client @ 2.9.5 with reactotron-react-native @ 5.1.9? If so, how?

or do we need to wait for an update to reactotron-react-native?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants