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.

[TypeScript] Paper with component=Link

See original GitHub issue

I might be doing something wrong, but I cannot use component Link with Paper.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Getting the following exception:

Type '(props: LinkRouter) => JSX.Element' is not assignable to type '"object" | "meter" | "textarea" | "button" | "style" | "progress" | "ruby" | "table" | "small" | "sub" | "embed" | "pre" | "caption" | "menu" | "menuitem" | "a" | "abbr" | "address" | ... 101 more ... | undefined'.
  Type '(props: LinkRouter) => JSX.Element' is not assignable to type 'FunctionComponent<HTMLAttributes<HTMLElement>>'.
    Types of parameters 'props' and 'props' are incompatible.
      Type 'PropsWithChildren<HTMLAttributes<HTMLElement>>' is not assignable to type 'LinkRouter'.
        Property 'to' is missing in type 'HTMLAttributes<HTMLElement> & { children?: ReactNode; }' but required in type 'LinkProps<PoorMansUnknown>'.

Expected Behavior 🤔

I should be able to use any component with Paper.

Steps to Reproduce 🕹

Steps:

import React from "react";
import {Link as RouterLink, LinkProps as RouterLinkProps} from "react-router-dom";
import Link, {LinkProps} from "@material-ui/core/Link";
import Paper from "@material-ui/core/Paper";

type LinkRouter = RouterLinkProps & Omit<LinkProps, "component">

const LinkRouter = (props: LinkRouter) => <Link underline="none" component={RouterLink} {...props}/>

export default () => (
    <Paper component={LinkRouter} to="/page">Link</Paper>
)

It works as expected if I use Avatar instead.

Context 🔦

I’d like to keep classes and options from paper but use a link. It works fine without TypeScript…

Your Environment 🌎

Tech Version
Material-UI v4.9.14
React v16.13.1
Browser Chrome
TypeScript 3.9.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
saiki4116commented, Nov 27, 2020

@oliviertassinari I am picking this up

1reaction
cyrilchaponcommented, Nov 21, 2020

I’m encountering

Property ‘noValidate’ does not exist on type ‘IntrinsicAttributes & BoxProps & { children?: ReactNode; }’.

With a <Box component='form' noValidate />

Is that same underlying issue ? Or should I reopen separately ? @eps1lon @oliviertassinari

EDIT: For now, using kinda same hack

import { FunctionComponent, FormHTMLAttributes } from 'react'
import { Box, BoxProps } from '@material-ui/core'

type FormBoxProps = BoxProps & FormHTMLAttributes<HTMLFormElement>

export const FormBox: FunctionComponent<FormBoxProps> = (props) => (
  <Box {...props} component='form' />
)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[TypeScript] Paper with component=Link · Issue #21154 - GitHub
I'd like to keep classes and options from paper but use a link. It works fine without TypeScript... Your Environment. Tech, Version. Material ......
Read more >
Material UI - TS - component prop typing - Property 'x' does not ...
I would like to pass the target property to my Paper component to reach the underlying a component. // Next.js Link component <Link...
Read more >
Getting started with Angular
HTML · JavaScript · TypeScript ... Pass data to a child componentlink. Currently, the product list displays the name and description of each...
Read more >
react-native-paper-select - npm
This module includes a customizable multi-select and a single select component for React Native Paper. The package is both Android and iOS ...
Read more >
Documentation - JSX - TypeScript
jsx file extension. The react mode will emit React.createElement , does not need to go through a JSX transformation before use, and the...
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