-
Notifications
You must be signed in to change notification settings - Fork 52
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) Add typings #71
Comments
Hi.
Sure. |
Hello, I'll finally not create PR has I will finally not use your library due to performance issue over non small sheets. Any way I give you the typings I created. It's not complete but it's usable. (to put in an index.d.ts) declare module 'read-excel-file/node' {
import { PathLike } from 'fs';
import { Stream } from 'stream';
export type SchemaPropertyType =
| 'Integer'
| 'URL'
| 'Email'
| typeof Date
| typeof Number
| typeof Boolean;
export interface FinalSchemaProperty {
prop: string;
type: SchemaPropertyType;
required?: boolean;
parse?<T>(value: string): T;
validate?<T>(value: T): void;
}
export interface MiddleSchemaProperty {
prop: string;
type: Record<string, SchemaProperty>;
}
export type SchemaProperty = FinalSchemaProperty | MiddleSchemaProperty;
export interface SheetParsingOptions {
sheet?: number | string;
properties?: any;
rowMap?: any;
isColumnOriented?: boolean;
transformData?(data: any): any;
}
export interface SheetConvertOptions extends SheetParsingOptions {
schema: Record<string, SchemaProperty>;
}
export interface SheetNamesOptions {
getSheets: boolean;
}
export type SheetOptions = SheetParsingOptions | SheetNamesOptions;
export interface ParsedResult {
rows: any[];
errors: any[];
}
function readXlsxFile(
input: Stream | PathLike,
options?: SheetOptions
): Promise<ParsedResult>;
function readXlsxFile(
input: Stream | PathLike,
options: SheetConvertOptions
): Promise<ParsedResult>;
export default readXlsxFile;
} |
Ok. |
Hi @catamphetamine, thanks for working on this. Can we merge this into master, it would be helpful for TS users. I can submit a PR if wanted. |
Sure, TypeScript pull requests would be accepted, if there is another man reviewing them. |
Thanks, I put this in my project and it works. |
Hey, big deal with typings, but I'm not sure about
Readme says, the main script returns
So actually what we have here is And offered typings declare that return value is object with fileds Am I right? If not, fix me, pls |
Rows is an array of arrays when no schema is passed. Otherwise, it’s an
array of objects.
…On Sun, 7 Jun 2020 at 11:16, Artyom ***@***.***> wrote:
Hey, big deal with typings, but I'm not sure about
interface ParsedResult {
rows: any[];
errors: any[];
}
Readme says, the main script returns rows from promise, where:
rows is an array of rows, each row being an array of cells.
So actually what we have here is rows: any[][].
And offered typings declare that return value is object with fileds rows
and errors, but that's not true.
Am I right? If not, fix me, pls
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADUP33FM5ME7FG7E4Z3UV3RVNEEXANCNFSM4K3PCCCQ>
.
|
Ah, my bad, skipped JSON-part in Readme.
Although I don't know is it a good idea to concat type and interface |
What i understand is that only the Conclusion |
I've received a similar request today in another repo, so I decided to review the typings. The typings drafts are in the repo: The instructions for testing those typings would be:
Also, here's a copy-pasted "universal" version of those typings (one could place the following definitions, wrapped with // import { PathLike } from 'fs'
// import { Stream } from 'stream'
type BasicType =
| string
| number
| boolean
| typeof Date
| 'Integer'
| 'URL'
| 'Email'
interface SchemaEntryBasic {
prop: string;
type: BasicType;
oneOf?<T>: T[];
required?: boolean;
validate?<T>(value: T): void;
}
interface SchemaEntryParsed {
prop: string;
parse<T>: (value: string) => T?;
oneOf?<T>: T[];
required?: boolean;
validate?<T>(value: T): void;
}
// Implementing recursive types in TypeScript:
// https://dev.to/busypeoples/notes-on-typescript-recursive-types-and-immutability-5ck1
interface SchemaEntryRecursive {
prop: string;
type: Record<string, SchemaEntry>;
required?: boolean;
}
type SchemaEntry = SchemaEntryBasic | SchemaEntryParsed | SchemaEntryRecursive
export type Schema = Record<string, SchemaEntry>
export interface Error {
error: string;
row: number;
column: number;
value?: any;
type?: SchemaEntry;
};
type Cell = string | number | boolean | typeof Date
export type Row = Cell[]
type InputBrowser = File
type InputNode = any // Stream | PathLike // (string|Stream|Buffer)
export type Input = InputBrowser | InputNode
export interface ParsedObjectsResult {
rows: object[];
errors: Error[];
}
export interface ParseWithSchemaOptions {
schema: Schema;
transformData?: (rows: Row[]) => Row[];
sheet?: number | string;
}
export interface ParseWithoutSchemaOptions {
sheet?: number | string;
}
function readXlsxFile(input: Input, options: ParseWithSchemaOptions) : Promise<ParsedObjectsResult>;
function readXlsxFile(input: Input, options?: ParseWithoutSchemaOptions) : Promise<Row[]>;
export default readXlsxFile; @ChamNouki One thing I'm not sure about though is this Also, do all In the meantime, the official not-tested @ChamNouki Also, it says |
Hi @catamphetamine , The About exporting interfaces and types, it depends : You have to export types that will be used by the library users. If some types are just internal definition, no need to export them. You're wright |
there's a |
Added TypeScript definitions in |
@catamphetamine getting typescript errors:
|
I just upgraded to the 5.2.13 and still getting these errors:
|
@sinn1 published |
@soufianerafik-jd |
Yes, the issue I reported was on the read-excel-file@5.2.13. I just bumped the version to read-excel-file@5.2.14 and it works. Thank you so much for your help on this. 😄 |
Getting this error. ERROR in ../node_modules/read-excel-file/index.d.ts:13:1 - error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. 13 function readXlsxFile(input: Input, options: ParseWithSchemaOptions) : Promise; |
Solved with adding export to these functions (using this ver. read-excel-file@5.2.15). @catamphetamine
Instead of
|
@SafetyOwl Thx, published |
Hello Nikolay,
This library seems very very cool to use but unfortunately I can't because it lacks typings for typescript based project with unauthorized javascript import.
Never mind I start to create typings to be able to use it xD. Have you already considered adding typings to your project ? Do you want some help for ? I can PR my typings if you are interested into.
The text was updated successfully, but these errors were encountered: