Closed mauroerta closed 7 months ago
Thank you!! Didn't know how to fix that ๐ I saw you mentioned nuxt/ui#2140, it would be really helpful if you have a solution ๐
Thank you!! Didn't know how to fix that ๐ I saw you mentioned nuxt/ui#2140, it would be really helpful if you have a solution ๐
I'll work on it, I hope to open a PR soon
๐ Linked issue
No Linked Issue (I can create one in case it is needed)
โ Type of change
๐ Description
I wanted to contribute to this project, specifically, I wanted to pick this issue here, while working on it I saw the
@ts-expect-error
comments and I thought I could fix them easily in a separate PR since they're all related to the same error.The Problem
In 2 places the type definition was accepting a generic parameter
T
without any constraint and trying to access one of its properties:Solution
I thought about 2 approaches:
Solution 1. (Proposed solution)
Instead of accessing the property directly (
T['size']
) we can use a utility type that extracts the property value in case it exists:The utility type
GetObjectField
extracts the type ofsize
contained in the typeT
in caseT
is object-like,never
is returned otherwise.Solution 2
Simply constraint the type of the generic parameter:
This is the simplest way to fix it but I'm not aware if this was not done for some reason.
I chose to go for the Solution 1 because I didn't have to change anything in the type definition of the affected types, even though usually I'd have chosen the Solution 2
๐ Checklist