compromise icon indicating copy to clipboard operation
compromise copied to clipboard

TypeScript types for extending compromise-sentences

Open chrisshaw opened this issue 3 years ago • 5 comments

:wave: Hi all.

I seem to be running into this closed issue using:

{
    "compromise": "^13.11.1",
    "compromise-sentences": "^0.3.0",
    "typescript": "^4.0.0"
}

I extend and use it as so:

import nlp from "compromise"
import sentences from "compromise-sentences"

const sentenceNlp = nlp.extend(sentences)
const test = sentenceNlp("Let's just see what happens.")
console.debug(test.sentences().toPastTense())

But TypeScript is mad at me.

index.ts:7:20 - error TS2339: Property 'toPastTense' does not exist on type 'ExtendedDocument<{ sentences(n?: number): Sentences; }, {}, {}>'.

7 console.debug(test.sentences().toPastTense())
                                 ~~~~~~~~~~~

My tsconfig is minimal and uses ES Module interop

{
  "compilerOptions": {
    "module": "CommonJS",
    "target": "es6",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "skipLibCheck": true,
    "esModuleInterop": true
  },
  "exclude": ["node_modules"]
}

Is is possible this has resurfaced? Or am I just being dumb?

chrisshaw avatar Apr 27 '21 16:04 chrisshaw

hi Chris, you're definitely not dumb. This stuff is very hard. I have no idea how @Drache93 figured out how to do this. He's basically the smartest person alive.

spencermountain avatar Apr 28 '21 16:04 spencermountain

😂 Definitely not the reason I noticed this message! If you want smart, check this website 😄 https://spencermounta.in/

So the previous issue was the overloading. However when I try your example, I'm seeing 'sentences' as 'any'

image

Could be my setup. Otherwise something broken in the typings.

Edit: Ah I see your error complains with correct thing, I'll fix mine and try again!

Drache93 avatar Apr 28 '21 18:04 Drache93

Working fine on a fresh install:

image

Same result with your tsconfig.json also.

Drache93 avatar Apr 28 '21 19:04 Drache93

:thinking: Well that's confusing. I've uninstalled, reinstalled, wiped node_modules, cloned a fresh repo. I have not spun up a new machine and tried it there to be fair.

Maybe different typescripts?

npm exec -- tsc -v
Version 4.2.4

But I also tested on 4.0.6 and still get the error. My VS Code TS server is 4.2.3.

image

It's not a huge issue as my use case is rather simple and I can just mangle the types but it sure is curious.

chrisshaw avatar May 02 '21 20:05 chrisshaw

Update: okay, well, now I have installed on a fresh Ubuntu machine and it works. So... no idea what in my local setup would be causing this.

Wish me happy hunting! Any ideas? ~Maybe something in my VS Code config?~ Edit: it's not that, I forgot I'd debugged this from the terminal too.

chrisshaw avatar May 02 '21 21:05 chrisshaw