v2.1.1 Typescript error: Property '$as' is missing in type
See original GitHub issueHello. We have upgraded the package from 2.0.4 to 2.1.1 and received new typescript errors all over the codebase. Most of them indicate some kind of issue with the new $as
prop. For example:
src/components/Navigation/NavBar.tsx(225,12): error TS2769: No overload matches this call.
Overload 1 of 2, '(props: { onClick?: MouseEventHandler<HTMLAnchorElement> | undefined; className?: string | undefined; color?: string | undefined; id?: string | undefined; ... 262 more ...; $active?: boolean | undefined; } & { ...; } & { ...; }): ReactElement<...>', gave the following error.
Property '$as' is missing in type '{ children: TFunctionResult; onClick: () => void; }' but required in type '{ onClick?: MouseEventHandler<HTMLAnchorElement> | undefined; className?: string | undefined; color?: string | undefined; id?: string | undefined; ... 262 more ...; $active?: boolean | undefined; }'.
Overload 2 of 2, '(props: StyledComponentPropsWithAs<TailwindComponent<Pick<Pick<ClassAttributes<HTMLAnchorElement> & AnchorHTMLAttributes<HTMLAnchorElement>, "key" | keyof AnchorHTMLAttributes<...>> & RefAttributes<...>, "key" | keyof AnchorHTMLAttributes<...>> & RefAttributes<...>>, ... 4 more ..., TailwindComponent<...>>): ReactElement<...>', gave the following error.
Property '$as' is missing in type '{ children: TFunctionResult; onClick: () => void; }' but required in type '{ onClick?: MouseEventHandler<HTMLAnchorElement> | undefined; className?: string | undefined; color?: string | undefined; id?: string | undefined; ... 262 more ...; $active?: boolean | undefined; }'.
The source code is as simple as follows:
const LogInAnchor = tw.a`
...
`
const TwAnchor = tw(LogInAnchor)`
...
`
const Anchor = styled(TwAnchor)<{ $active?: boolean }>`
...
`
// later, error at the render site
<Anchor>Logout</Anchor>
By looking at the library’s source code I couldn’t understand why is the $as
prop reported as missing, since it seems to be optional. Do you have any idea why this error occurs and how to fix it?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Property is missing in type 'X' but required in type 'Y' | bobbyhadz
The TypeScript error "Property is missing in type but required in type" occurs when we do not set all of the properties an...
Read more >TypeScript doesn't warn me that a property is missing #50845
The value you've provided is not a valid Data & Extra , but it is a valid Data (the types aren't exact, objects...
Read more >Typescript, react error Property '[Invalid_propTypes]' is missing ...
Suddenly all my antd components started to give the same error. "Property '[Invalid_propTypes]' is missing in type.
Read more >Documentation - Narrowing - TypeScript
JavaScript has an operator for determining if an object has a property with a name: the in operator. TypeScript takes this into account...
Read more >types of property incompatible error in react & typescript
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ok sorry I was actually able to reproduce after putting
strict: true
in my tsconfig.Some of the $as prop declaration were missing an optional
?
character.It’s now fixed on the version 2.1.2
Thank you for reporting this issue!
@MathiasGilson
Yeah sorry, I noticed the issue comes up when strict=true in tsconfig as well.
Unfortunately there are also some very rare weird edge cases I also noticed that only occur when strict is true, these happen even in pre 2.1.0 versions. Like I get an error when using
tw
on a Component without aclassName
prop.And also optional props added using type constructors(?) get stripped out.
I am working on a PR that has fixed these but I want to test further to be sure.