wtf_wikipedia icon indicating copy to clipboard operation
wtf_wikipedia copied to clipboard

Document not exported

Open hulluP opened this issue 2 years ago • 2 comments

Hi I am trying to consume this plugin from typescript. And I am struggling a little as the return type Document for the function fetch is not exported ! Code example:

async getHello(): Promise<string> {
     const doc = await fetch("Tisch", {
        lang: "de",
      });

      console.log(doc['_title']);
    return doc['_title'];

The above is a workaround that I parse the result myself. it would be nice though to be able to use the Document type. find the above code @ https://github.com/hulluP/parseWiki Could you please add it to the exported declaration

declare namespace wtf { var version : string export { fetch } export { extend } export { extend as plugin } export { version } }

Thanks

hulluP avatar Jul 22 '22 10:07 hulluP

hey @hulluP sure - can you make a pr? to be honest, a lot of this typescript stuff is over my head. happy to make any suggested changes cheers

spencermountain avatar Jul 22 '22 14:07 spencermountain

hi - is the issue using fetch() instead of wtf.fetch()? by my (limited) understanding of ts, the Document seems to be returned by the fetch function lemme know, thanks

spencermountain avatar Jul 26 '22 19:07 spencermountain

I can shine some light on this issue.

In typescript, you need to declare return types for functions. The type can be a class, so what I expect that the user wants is to use the document class as a type.

example code

import {fetch, Document} from 'wtf_wikipedia'

async function fetchDocument(name: string): Document | Document[] {
    return await fetch('Manhattan_(New_York)') ?? []
}

This code fails because (also in normal js) the Document class is not exported.

The fix for this is simple to export the Document class in the index.js. And then a small upgrade of the types file.

I will be looking at the issue so expect a pr in a few days

wvanderp avatar Oct 07 '22 10:10 wvanderp