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.

getting "error TS2677: A type predicate's type must be assignable to its parameter's type."

See original GitHub issue

Versions

  • System: linux
  • NodeJS: 14.18.0
  • Typescript: 4.9.3
  • Compiler / Transpiler: tsc
  • Typegoose(NPM): ^9.13.0
  • Typegoose(GIT): commithash
  • mongoose: 6.7.3

What is the Problem?

npm run tsc fails to build with this error:


node_modules/@typegoose/typegoose/lib/typeguards.d.ts:8:82 - error TS2677: A type predicate's type must be assignable to its parameter's type.
  Type 'T extends DocumentType<infer T1, infer T2> ? DocumentType<T1, T2> : T extends object ? DocumentType<T, BeAnObject> : never' is not assignable to type 'Ref<T, S>'.
    Type 'DocumentType<unknown, unknown> | (T extends object ? DocumentType<T, BeAnObject> : never)' is not assignable to type 'Ref<T, S>'.
      Type 'DocumentType<unknown, unknown>' is not assignable to type 'Ref<T, S>'.
        Type 'DocumentType<unknown, unknown>' is not assignable to type 'S'.
          'S' could be instantiated with an arbitrary type which could be unrelated to 'DocumentType<unknown, unknown>'.

8 export declare function isDocument<T, S extends RefType>(doc: Ref<T, S>): doc is T extends DocumentType<infer T1, infer T2> ? DocumentType<T1, T2> : T extends object ? DocumentType<T> : never;

Do you know why it happens?

no


Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hasezoeycommented, Nov 28, 2022

i just noticed that the hotfix works as long as the source-file is directly used, but the declaration file (compiled output) does not work because it did not actually transfer the @ts-ignore

so the only workaround is to use a older typescript version (being 4.8) and waiting for typegoose 10.0 (beta build coming soon) which updated those types to work on typescript 4.9

0reactions
hasezoeycommented, Dec 3, 2022

The Typescript issue i had opened has been closed as “not planned” (and more or less “working as intended”), so there will be no fix for typescript 4.9 for typegoose 9.x, see https://github.com/microsoft/TypeScript/issues/51638; continue to use typescript 4.8 as a workaround

Note: typegoose 10.0 will have typescript 4.9 support (and minimal requirement) and a beta has already been released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why must a type predicate's type be assignable to its ...
A user-defined type guard performs a runtime check to determine whether or not value of a particular type satisfies a type predicate.
Read more >
error: A type predicate's type must be assignable to its ...
ts(577,74): error TS2677: A type predicate's type must be assignable to its parameter's type. Type 'EmptyObjectOf<T>' is not assignable to type ...
Read more >
TypeScript Type Guards and Type Predicates
This works and will error when we refactor Article and remove the content property. Functions that are declared as type predicate, must return...
Read more >
A Type Predicate's Type Must Be Assignable To Its Parameter's ...
I'm making an attempt to make my angular mission construct But I'm dealing with the next error TS2677: A type predicate's type must...
Read more >
Advanced TypeScript: Type predicates in filter
Welcome to the Type predicates in filter lesson! ... If we try to assign that array to a variable of type number[] ,...
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