ffMathy / FluffySpoon.JavaScript.Testing.Faking

An NSubstitute port to TypeScript called substitute.js.
MIT License
202 stars 22 forks source link

Substitute.d.ts(6,35): error TS2344: Type 'T' does not satisfy the constraint 'Object' #241

Closed Cafe137 closed 2 years ago

Cafe137 commented 2 years ago

Describe the bug

I am on version 1.208.0 using Typescript 4.8.3 and running tsc gives the following type error:

Error: node_modules/@fluffy-spoon/substitute/dist/src/Substitute.d.ts(6,35): error TS2344: Type 'T' does not satisfy the constraint 'Object'.

node_modules/@fluffy-spoon/substitute/dist/src/Substitute.d.ts Line 6:

image
notanengineercom commented 2 years ago

👋 Hi! Could you try installing the beta release, and check if that issue persists? You can install it via npm as described here.

npm i @fluffy-spoon/substitute@beta
AuHau commented 2 years ago

EDIT: I meant TS 4.8 not 3.8 😅

Hey 👋

Yes, the issue is present in the substitute@beta.1 see the issues:

node_modules/@fluffy-spoon/substitute/dist/src/Substitute.d.ts:15:35 - error TS2344: Type 'T' does not satisfy the constraint 'Object'.

15     static for<T>(): SubstituteOf<T>;
                                     ~

  node_modules/@fluffy-spoon/substitute/dist/src/Substitute.d.ts:15:16
    15     static for<T>(): SubstituteOf<T>;
                      ~
    This type parameter might need an `extends Object` constraint.

node_modules/@fluffy-spoon/substitute/dist/src/Substitute.d.ts:16:46 - error TS2344: Type 'unknown' does not satisfy the constraint 'Object'.

16     static disableFor<T extends SubstituteOf<unknown> & Instantiable<Substitute>>(substituteProxy: T): DisabledSubstituteObject<T>;
                                                ~~~~~~~

Found 2 errors in the same file, starting at: node_modules/@fluffy-spoon/substitute/dist/src/Substitute.d.ts:15

The first issue solves my PR #242 (I have tested that locally), but the second issue about the disableFor() I am not sure how to really solve.

I would suggest you to bump to TS 3.8 and test it yourself ;-)

notanengineercom commented 2 years ago

Hmm ok, I see where the confusion comes from. This issue mentions typescript 4.8.3, but your PR targets version 3.8. I see this as two separate issues:

I will leave this issue open for a few days, but to me it seems this issue is solved by using the beta

AuHau commented 2 years ago

Oh fuck, sorry my bad 🙈 I am targeting TS 4.8 (pretty much the latest), not sure how I mixed it up for 3.8. I will fix it in the PR title.

Sorry about the confusion, but then no using beta does not solves this issue ;-)

notanengineercom commented 2 years ago

No worries! Hmm I'm unable to reproduce it locally. What's your tsconfig? I think this might be related to the strict modes

notanengineercom commented 2 years ago

Hi @Cafe137 and @AuHau, could you try with the latest beta relase? https://www.npmjs.com/package/@fluffy-spoon/substitute/v/2.0.0-beta.2 I think the issue you were facing was caused because the library wasn't able to transpile in typescript strict mode. Now it does

notanengineercom commented 2 years ago

I think this issue should have been fixed here https://github.com/ffMathy/FluffySpoon.JavaScript.Testing.Faking/pull/244 Please reopen in case the problems persist