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

TypeScript errors with v4 #81

Closed
HitomiTenshi opened this issue Jun 5, 2022 · 17 comments · Fixed by #82
Closed

TypeScript errors with v4 #81

HitomiTenshi opened this issue Jun 5, 2022 · 17 comments · Fixed by #82

Comments

@HitomiTenshi
Copy link

The latest version results in a bunch of errors when TypeScript is configured with the following settings:

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2020",
    "module": "es2020",
    "lib": ["es2020", "dom"],
    "types": ["node"]
  }
}

Errors when trying to compile:

Error: node_modules/fast-equals/src/index.ts:48:7 - error TS2322: Type 'Readonly<CreateComparatorCreatorOptions<undefined> & { areArraysEqual: (a: any[], b: any[], isEqual: InternalEqualityComparator<any>, meta: any) => boolean; areMapsEqual: (a: Map<...>, b: Map<...>, isEqual: InternalEqualityComparator<...>, meta: any) => boolean; areObjectsEqual: (a: Dictionary<...>, b: Dictionary<.....' is not assignable to type 'CreateComparatorCreatorOptions<WeakMap<object, any>>'.
  Types of property 'areDatesEqual' are incompatible.
    Type 'TypeEqualityComparator<Date, undefined>' is not assignable to type 'TypeEqualityComparator<Date, WeakMap<object, any>>'.
      Types of parameters 'isEqual' and 'isEqual' are incompatible.
        Types of parameters 'meta' and 'meta' are incompatible.
          Type 'undefined' is not assignable to type 'WeakMap<object, any>'.

48 const DEFAULT_CIRCULAR_CONFIG: CreateComparatorCreatorOptions<
         ~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/fast-equals/src/index.ts:113:48 - error TS2345: Argument of type 'CreateComparatorCreatorOptions<undefined>' is not assignable to parameter of type 'CreateComparatorCreatorOptions<Meta>'.
  Types of property 'areArraysEqual' are incompatible.
    Type 'TypeEqualityComparator<any[], undefined>' is not assignable to type 'TypeEqualityComparator<any[], Meta>'.
      Types of parameters 'isEqual' and 'isEqual' are incompatible.
        Types of parameters 'meta' and 'meta' are incompatible.
          Type 'undefined' is not assignable to type 'Meta'.
            'Meta' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.

113     merge(DEFAULT_CONFIG, getComparatorOptions(DEFAULT_CONFIG)),
                                                   ~~~~~~~~~~~~~~


Error: node_modules/fast-equals/src/objects.ts:39:33 - error TS4111: Property '$$typeof' comes from an index signature, so it must be accessed with ['$$typeof'].

39       const reactElementA = !!a.$$typeof;
                                   ~~~~~~~~


Error: node_modules/fast-equals/src/objects.ts:40:33 - error TS4111: Property '$$typeof' comes from an index signature, so it must be accessed with ['$$typeof'].

40       const reactElementB = !!b.$$typeof;
                                   ~~~~~~~~


Error: node_modules/fast-equals/src/utils.ts:38:5 - error TS6133: 'indexOrKeyA' is declared but its value is never read.
38     indexOrKeyA: any,
       ~~~~~~~~~~~


Error: node_modules/fast-equals/src/utils.ts:39:5 - error TS6133: 'indexOrKeyB' is declared but its value is never read.
39     indexOrKeyB: any,
       ~~~~~~~~~~~


Error: node_modules/fast-equals/src/utils.ts:40:5 - error TS6133: 'parentA' is declared but its value is never read.

40     parentA: any,
       ~~~~~~~


Error: node_modules/fast-equals/src/utils.ts:41:5 - error TS6133: 'parentB' is declared but its value is never read.

41     parentB: any,
       ~~~~~~~

I already tried adding "skipLibCheck": true to compilerOptions but it did not fix it.

Downgrading to version v3.0.3 fixes this issue.

@danielweck
Copy link

Similar issues with TypeScript 4.8.0-dev.20220605 (NPM release tag next)

(same errors with skipLibCheck in tsconfig.json)

../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/index.ts:48:7 - error TS2322: Type 'Readonly<CreateComparatorCreatorOptions<undefined> & { areArraysEqual: (a: any[], b: any[], isEqual: InternalEqualityComparator<any>, meta: any) => boolean; areMapsEqual: (a: Map<any, any>, b: Map<any, any>, isEqual: InternalEqualityComparator<any>, meta: any) => boolean; areObjectsEqual: (a: Dictionary<any>, b: Dictionary<any>, isEqual: InternalEqualityComparator<any>, meta: any) => boolean; areSetsEqual: (a: Set<any>, b: Set<any>, isEqual: InternalEqualityComparator<any>, meta: any) => boolean; }>' is not assignable to type 'CreateComparatorCreatorOptions<WeakMap<object, any>>'.
  Types of property 'areDatesEqual' are incompatible.
    Type 'TypeEqualityComparator<Date, undefined>' is not assignable to type 'TypeEqualityComparator<Date, WeakMap<object, any>>'.
      Types of parameters 'isEqual' and 'isEqual' are incompatible.
        Types of parameters 'meta' and 'meta' are incompatible.
          Type 'undefined' is not assignable to type 'WeakMap<object, any>'.

48 const DEFAULT_CIRCULAR_CONFIG: CreateComparatorCreatorOptions<
         ~~~~~~~~~~~~~~~~~~~~~~~

../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/index.ts:113:48 - error TS2345: Argument of type 'CreateComparatorCreatorOptions<undefined>' is not assignable to parameter of type 'CreateComparatorCreatorOptions<Meta>'.
  Types of property 'areArraysEqual' are incompatible.
    Type 'TypeEqualityComparator<any[], undefined>' is not assignable to type 'TypeEqualityComparator<any[], Meta>'.
      Types of parameters 'isEqual' and 'isEqual' are incompatible.
        Types of parameters 'meta' and 'meta' are incompatible.
          Type 'undefined' is not assignable to type 'Meta'.
            'Meta' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.

113     merge(DEFAULT_CONFIG, getComparatorOptions(DEFAULT_CONFIG)),
                                                   ~~~~~~~~~~~~~~

../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/utils.ts:38:5 - error TS6133: 'indexOrKeyA' is declared but its value is never read.

38     indexOrKeyA: any,
       ~~~~~~~~~~~

../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/utils.ts:39:5 - error TS6133: 'indexOrKeyB' is declared but its value is never read.

39     indexOrKeyB: any,
       ~~~~~~~~~~~

../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/utils.ts:40:5 - error TS6133: 'parentA' is declared but its value is never read.

40     parentA: any,
       ~~~~~~~

../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/utils.ts:41:5 - error TS6133: 'parentB' is declared but its value is never read.

41     parentB: any,
       ~~~~~~~


Found 6 errors in 2 files.

Errors  Files
     2  ../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/index.ts:48
     4  ../../node_modules/.pnpm/[email protected]/node_modules/fast-equals/src/utils.ts:38

@HitomiTenshi
Copy link
Author

I forgot to mention that I tested typescript v4.6.4 and v4.7.3, errors occur on both versions.

@planttheidea
Copy link
Owner

Yup, looks like the additional stricter options are calling it out. I've published a new beta (4.0.1-beta.0) with some fixes for it. If you want to download and try it out locally (npm i fast-equals@next) and let me know I'd appreciate it. Once you confirm the lack of typing issues, I can publish posthaste.

cc: @HitomiTenshi @danielweck

@HitomiTenshi
Copy link
Author

I now get a bunch of warnings, but in general it seems to work:

The warnings:

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/arrays.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/comparator.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/dates.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/index.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/maps.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/objects.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/regexps.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/sets.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/utils.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

@HitomiTenshi
Copy link
Author

@planttheidea I think this issue occurs because you changed the index.d.ts file to import actual .ts files which are then considered for compilation.

@planttheidea
Copy link
Owner

@HitomiTenshi that was something of an intentional decision, to avoid duplication and potential type drifting. Lemme do some investigation, but I'll get this out today.

@HitomiTenshi
Copy link
Author

@planttheidea Adding "declaration": true to compilerOptions in your tsconfig.json might already do the trick. You'd have to commit / publish the .d.ts files as well for it to work though.

@planttheidea
Copy link
Owner

planttheidea commented Jun 5, 2022

@HitoriSensei - I believe it may be related to the fact that the fast-equals tsconfig.json had an includes definition pointing to src, which was not necessary. I've published an update to the beta patch (4.0.1-beta.1), and consuming it as a dependency with the same options you have above does not give me any errors. Give that a try and let me know if the warnings stop.

@HitomiTenshi
Copy link
Author

I'm still getting the same warnings with version 4.0.1-beta.1. Just tested it.

@planttheidea
Copy link
Owner

Alright, take 3! Appreciate you helping debug this with me @HitomiTenshi .

Another hypothesis is that it is the consumption of runtime files that is causing the warning, so I've split out all the types definitions to their own file (src/types.ts) and now index.d.ts only imports from that file. Give 4.0.1-beta.2 a try!

@HitomiTenshi
Copy link
Author

HitomiTenshi commented Jun 5, 2022

@planttheidea Progress! Now I only get a single warning:

Warning: C:/Users/fegit1/Documents/Apps/sms-portal-reborn/node_modules/fast-equals/src/types.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Edit: Maybe it really is the thing I mentioned, have you tried generating the .d.ts files? Since they are only definitions and no logic, that would probably solve the file is part of the compilation warnings.

@planttheidea
Copy link
Owner

planttheidea commented Jun 5, 2022

Haha damn, it really doesn't like to import in that file! Alright one more, and I'm bullish on this one. I flipped the script, and made index.d.ts the source of all the types instead of that separate src/types.ts file, making it the source of truth for all types, including for development. Consider it the above attempt minus the additional file generation (I am trying to avoid that, if possible).

I feel confident about 4.0.1-beta.3. If this doesn't work, then I'll attempt the declaration config approach, but I would be very surprised if that worked and this most recent beta doesn't.

@HitomiTenshi
Copy link
Author

@planttheidea It works! 🥳 🎉

Although I'm curious if reverting your commit 89f5637 where you put a bunch of any types into TypeEqualityComparator will cause errors with strict configurations again. Usually you shouldn't have to modify your own tsconfig.json settings for other external projects. This could happen again with future settings that Microsoft adds to TypeScript.

@planttheidea
Copy link
Owner

@HitomiTenshi - I definitely still get errors, and the strict checking locally still works as expected. I think this was a naivete on my end related to the limitations of *.d.ts files. A little searching quickly explained to me that by import-ing anything, it turned the file into a module, which we don't want! In reality, I don't think the tsconfig.json was the problem (more an effect than a cause), however I actually like the strictness options you applied, so I would like to keep it as a steady state. :)

I'll publish the proper patch shortly.

@HitomiTenshi
Copy link
Author

@planttheidea With the latest npm package all errors disappeared for me, although I'm not using all of the functionality that this library provides.

I'm still here to test if you need to, just add another comment when it's ready 😄 Thanks for all the hard work on a Sunday at this late time! (For me it is already 12:17 AM, CEST timezone).

@planttheidea
Copy link
Owner

@HitomiTenshi - your help was greatly appreciated, and at a very late hour for you on top of that! Well, the fruits of our labor are available in 4.0.1, which I just published. If you have any more issues, let me know!

@danielweck
Copy link

Fixed now, thank you :)

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 a pull request may close this issue.

3 participants