Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Type definitions #8

Open
dantonel opened this issue Mar 25, 2020 · 6 comments
Open

Type definitions #8

dantonel opened this issue Mar 25, 2020 · 6 comments

Comments

@dantonel
Copy link

Are there any typescript typedefinitions available for this package? I tried grabbing the type definitions directly from the 'styled-components' package:

declare module '@react-pdf/styled-components'
{
  export * from '@types/styled-components';
}

or

declare module '@react-pdf/styled-components'
{
  export { default } from '@types/styled-components';
}

but I still get type errors like:
Property 'Text' does not exist on type 'typeof import("@react-pdf/styled-components")'.
or
Type 'Style' is not assignable to type 'CSSProperties'

@luskin
Copy link

luskin commented Jul 27, 2020

has anybody found a way to use this package properly with Typescript?

@kayotimoteo
Copy link

Same problem here, thanks.

@mbagatini
Copy link

I have the same problem. Please guys it would be awesome to use it with Typescript. Thanks!

@ianwensink
Copy link

I would like this as well.

For now I've done what the OP suggested, and then use the declarations differently. Instead of using styled.Page, I use styled(Page) which has the same result but now with types.

npm install -D @types/styled-components
declare module '@react-pdf/styled-components' {
  export { default } from 'styled-components';
}
import { Page } from '@react-pdf/renderer';

const StyledPage = styled(Page)`
  background-color: #E4E4E4;
`;

const MyDocument = () => (
  <StyledPage size="A4"></StyledPage>
);

Now <StyledPage /> inherits types from Page so props like size are typed.

@diegomura
Copy link
Contributor

Hey! Wanted to ask. How much are you using the styled components interface for react-pdf and how good did it work?
The reason why I ask it it's because this whole package it's mostly a hack rather than a good supported bind. It uses and old styled-components version (with the last it's not even possible to work as far as I saw) and ships a lot of extra code if used in the browser. It will keep published but I don't think I'll have time to maintain it, specially considering it does not depend 100% on my project but rather styled-components. Hope you understand but I still want to hear your thoughts :)

@luskin
Copy link

luskin commented Mar 2, 2021

@diegomura it's working great for us as is, we are generating thousands of documents daily with this approach and IMHO styled-components is really the future for any kind of design work on the front-end. It would be great if we could come together to support styled-components officially.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants