-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
TypeScript and definitions. #51
Comments
Hey! Thanks for asking. |
Hey! No prob! I don't mean to be that guy. |
Adding typings does not require you to convert any JavaScript to TypeScript Providing typings is just additional metadata that is fed into the TypeScript compiler so that people who write projects in TypeScript can consume your JavaScript library with strong typing guarantees To provide these in your project, you would add More and more people are starting new projects as TypeScript and only consuming libraries which expose TypeScript type information, and I can attest, it makes web development so much smoother. I'd like to use this project, but a lack of typings prevents me from doing so. If none of the other alternative PDF.js based React components don't either, I'll probably bite the bullet and create typings and contribute them back |
Hmmmm, I don't know if I feel confident enough to do it right now, but it is indeed an interesting idea, so I'm going to keep this issue open in case me or anyone else would like to have some fun with it! |
@alex-sherwin did you get a chance to create typings for this package? If so, can you maybe share them or issue a PR maybe? |
Hi @dimon82 I did not end up using this project at all. I used npm packages |
Anyone still stuck at the transpiler errors, add this as a bare minimum. You won't get any intellisense support. @types
|
For those who are using Flow, I published |
@danno-ax : Can u please share/publish your typescript definition for react-pdf. |
I've started learning some TypeScript as well... once v3 is out of alpha/beta, I can look into updating the Flow definitions as well as creating some TypeScript definitions. |
I threw together some basic TS typings that I'm using on my project. They're not well tested, but they could serve as a starting point:. This is for //@types/react-pdf/index.d.ts
declare module 'react-pdf' {
import * as React from 'react';
interface CommonPdfProps {
error?: React.ReactNode | Function;
// TODO: Change to real ref type
inputRef?: (ref: any) => void;
loading?: React.ReactNode | Function;
noData?: React.ReactNode | Function;
onLoadError?: (error: Error) => void;
onLoadSuccess?: (pdf: Pdf) => void;
}
interface Pdf {
numPages: number;
}
interface DocumentProps extends CommonPdfProps {
file: string | File;
onItemClick?: (pageNumber: number) => void;
onSourceError?: (error: Error) => void;
rotate?: 0 | 90 | 180 | 270;
}
class Document extends React.Component<DocumentProps>{}
interface PageProps extends CommonPdfProps {
customTextRenderer?: (args: { str: string, itemIndex: number }) => React.ReactNode;
onRenderError?: (error: Error) => void;
onRenderSuccess?: () => void;
// TODO: Add array typings
onGetAnnotationsSuccess?: (annotations: any[]) => void;
onGetAnnotationsError?: (error: Error) => void;
// TODO: Add array typings
onGetTextSuccess?: (items: any[]) => void;
onGetTextError?: (error: Error) => void;
pageIndex?: number;
pageNumber?: number;
renderAnnotations?: boolean;
renderTextLayer?: boolean;
rotate?: 0 | 90 | 180 | 270;
scale?: number;
width?: number;
}
class Page extends React.Component<PageProps>{}
interface OutlineProps {
onItemClick?: (pageNumber: number) => void;
onLoadError?: (error: Error) => void;
onLoadSuccess?: (pdf: Pdf) => void;
onParseError?: (error: Error) => void;
// TODO: Add array typings
onParseSuccess?: (outline: any[]) => void;
}
class Outline extends React.Component<OutlineProps>{}
} It would be great to include some typings in the project. Material UI is a good example of coding in JS but including TS definitions: https://github.com/mui-org/material-ui/tree/v1-beta/packages/material-ui/src UPDATE I changed |
You're most likely better off leaving it as But nice work with the declaration! |
@alex-sherwin pdfjs is better than this? |
@saadq I tried. but error...
|
could you append them in the file?
Will you do pull-request to |
Hey @moffsugita, in regards to this message:
This usually means that the flow project you are currently in is missing a |
@moffsugita I will not since I don't feel like an expert in that matter. As I said, I welcome all PRs though, so if anyone would like to add typings to this repo, I will certainly appreciate it. |
Hello @saadq I created
edited
ran
|
@saadq Perhaps. I had should append your module's version when run install command like below.
it pulled to however... my project (create-react-app created) didn't recognize the file yet.
|
@saadq perhaps.. |
Finally. It is my good practice which I thought before releasing type file in I created files in the project.
|
@moffsugita So both Flow and TypeScript are two separate typecheckers people use for projects. TypeScript is both the type checker and compiler while Flow is just the type checker ( So the problem you ran into with Flow is that |
Hi all, I have just contributed |
Im wondering if typings could be added/maintained for this project? Iv got a patch almost ready to go in my own repo i could add it?
Would it be too bold of me to even propose a conversion to TS?
The text was updated successfully, but these errors were encountered: