-
Notifications
You must be signed in to change notification settings - Fork 7
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
Would you consider adding Typescript type definitions? #15
Comments
I will add @types to avoid TypeScript errors as soon as possible. Thank you for your feedback! |
FWIW here are the types I created for my use of the return await rraList(dirPath, options); types: export type DiscoveredFilesResult = Array<FileDiscoveredItem> | Array<RecursiveReaddirSysError> | Array<RecursiveReaddirFileError>;
export interface FileDiscoveredItem {
name: string;
path: string;
fullname: string;
isDirectory: boolean;
}
export interface RecursiveReaddirSysError {
error: {
message: string;
errno: number;
code: string;
syscall: string;
path: string;
};
path: string;
}
export interface RecursiveReaddirFileError {
name: string;
title: string;
path: string;
fullname: string;
error: object;
} Had to define this function as well to get Typescript to realize when the result is not an error: function isFileDiscoveredItemArray(
item: DiscoveredFilesResult
): item is Array<FileDiscoveredItem> {
return !("error" in item[0]);
} which comes from https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards. |
@m0rtadelo Are you still planning on doing this? I hit a |
Hello.
Sorry i am a little busy and can't work on this now. MR's will be accepted.
Missatge de Ari Kalfus <notifications@github.com> del dia dv., 15 de gen.
2021 a les 19:21:
… @m0rtadelo <https://github.com/m0rtadelo> Are you still planning on doing
this? I hit a undefined result issue that I am pretty sure would be
prevented if the types I defined for this library were accurate :D
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGFH3THWZQXHYNLZTRZAFF3S2CBQ7ANCNFSM4SJAHR2A>
.
|
That is fair! |
Version 1.2.0 has been written totally in typescript and works with types in typescript projects as expected. Sorry for the wait |
I saw #7 adding support for ES6 modules, which is convenient. I currently use this library in a Typescript project via
Typescript throws a compilation error (that I have to ignore) saying:
I am not super familiar on how to do that myself, but I see many projects have type definitions under
@types
. The documentation for that appears to be https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#publish-to-types. This page also has some documentation on how to build in typescript types natively to your library.Is this something you'd consider doing? Would be a convenience when using this library with typescript. I currently suppress the error with:
The text was updated successfully, but these errors were encountered: