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

Compilation error on index.d.cts #488

Open
JbIPS opened this issue Jul 23, 2024 · 3 comments
Open

Compilation error on index.d.cts #488

JbIPS opened this issue Jul 23, 2024 · 3 comments
Labels
Status: Awaiting Response Issue or PR awaits response from the creator. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.

Comments

@JbIPS
Copy link

JbIPS commented Jul 23, 2024

Bug Report

On a project with deepmerge-ts as a depency and skipLibCheck to false, this error pops at compile time

> tsc -p .

node_modules/deepmerge-ts/dist/node/index.d.cts:437:127 - error TS2344: Type '{ 
[I in keyof Ts]: Ts[I] extends { key: infer Key extends PropertyKey; values: inf
er Values extends readonly unknown[]; optional: infer O extends boolean; } ? Cre
ateRecordForKeyFromMeta<Key, Values, O, Fs, M> : never; }' does not satisfy the 
constraint 'readonly unknown[]'.
  Types of property 'length' are incompatible.
    Type 'Ts["length"] extends { key: infer Key extends PropertyKey; values: inf
er Values extends readonly unknown[]; optional: infer O extends boolean; } ? Cre
ateRecordForKeyFromMeta<Key, Values, O, Fs, M> : never' is not assignable to typ
e 'number'.
      Type '{ [x: string]: unknown; [x: number]: unknown; [x: symbol]: unknown; 
} | { [x: string]: unknown; [x: number]: unknown; [x: symbol]: unknown; }' is no
t assignable to type 'number'.
        Type '{ [x: string]: unknown; [x: number]: unknown; [x: symbol]: unknown
; }' is not assignable to type 'number'.

437 type CreateRecordFromMeta<Ts, Fs extends DeepMergeFunctionsURIs, M> = Ts ext
ends ReadonlyArray<unknown> ? TupleToIntersection<{
                                                                                
                                                  ~
438     [I in keyof Ts]: Ts[I] extends {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
442     } ? CreateRecordForKeyFromMeta<Key, Values, O, Fs, M> : never;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
443 }> : never;

Expected behavior

It should compile

Actual behavior

It does not

Steps to reproduce

  • npm i deepmerge-ts@latest (7.0.3 is also affected)
  • ensure in tsconfig.json that you have "skipLibCheck": false
  • `tsc

Proposed changes

Adding "skipLibCheck": false on the main project is a workaround, but I find it a bit hacky, thus this report

@JbIPS JbIPS added Status: Triage This issue needs to be triaged. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors. labels Jul 23, 2024
JbIPS added a commit to JbIPS/node-soap that referenced this issue Jul 23, 2024
`deepmerge-ts` seems to have an
[issue](RebeccaStevens/deepmerge-ts#488) with
a type file.

Skipping lib check in `tsconfig.json`
([doc](https://www.typescriptlang.org/tsconfig/#skipLibCheck)) works
around that and will increase compile time without drawbacks.
@fatihaziz
Copy link
Contributor

fatihaziz commented Aug 2, 2024

could you reproduce the problem with code example?
It seems your code has too complicated types, let me see how you use the deepmerge function like

@fatihaziz
Copy link
Contributor

sometimes what you need to do is using casting types for merging object with different types,
for example

types ObjectTypeA {
 prop_a: boolean
}

types ObjectTypeB {
 prop_b: boolean
}

types ObjectTypeC {
 prop_a?: boolean
 prop_b?: boolean 
}

let someobject_a: ObjectTypeA = {
prop_a: false
}

let someobject_b: ObjectTypeA = {
prop_b: false
}

// dont ❌
let someobject_c = deepmerge(someobject_a, someobject_b) // may throw type error, since the type between the two object not the same.

// todo ✅
let someobject_c: ObjectTypeC = deepmerge(someobject_a as ObjectTypeC, someobject_b as ObjectTypeC) // will fix it, and still get the correct type.

@RebeccaStevens
Copy link
Owner

RebeccaStevens commented Oct 8, 2024

I've updated how the types are compiled for this project. Hopefully, as a consequence, this has also fixed this issue. Let me know if you still have to issue.

Also, sorry for the long delay in my reply.

@RebeccaStevens RebeccaStevens added Status: Awaiting Response Issue or PR awaits response from the creator. and removed Status: Triage This issue needs to be triaged. labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting Response Issue or PR awaits response from the creator. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

3 participants