Skip to content
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

Improve TypeScript DX by reducing usage of "any" #1098

Open
simonbrunel opened this issue Mar 16, 2024 · 1 comment
Open

Improve TypeScript DX by reducing usage of "any" #1098

simonbrunel opened this issue Mar 16, 2024 · 1 comment

Comments

@simonbrunel
Copy link

I'm using compromise with TypeScript and I see myself casting quite often the output of this library (i.e. as string[]):

(nlp(input).sentences().out("array") as string[]).map((v) => process(v));
(nlp(input).sentences().map((doc) => process(doc.text())) as string[]);

This is caused by the use of a few any, that slightly degrades the TypeScript developer experience. I believe this could be improved, for example by using overloads and generics:

declare class View {
  out(format?: 'text' | 'normal' | 'root' | 'machine' | 'reduced' | 'hash' | 'md5'): string
  out(format: 'array'): string[]
  out(format: 'debug'): View
  // ...
}
declare class View {
  map: <T>(fn: (m: View) => T, emptyResult?: T) => T extends View ? View : T[]
}
@spencermountain
Copy link
Owner

spencermountain commented Mar 22, 2024

hey, thanks Simon - sorry for the delay.
Good idea! A PR is welcomed and really appreciated. I'm a klutz with typescript, and would really appreciate the help.
cheers

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

No branches or pull requests

2 participants