fast-xml-parser icon indicating copy to clipboard operation
fast-xml-parser copied to clipboard

Feature request: TypeScript Support

Open dkotrada opened this issue 4 years ago • 18 comments

Could you please provide TypeScript support? In particular https://deno.land/

dkotrada avatar May 20 '20 08:05 dkotrada

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

github-actions[bot] avatar May 20 '20 08:05 github-actions[bot]

You can watch the repo for new changes or star it.

Already starred it. 👍

dkotrada avatar May 20 '20 08:05 dkotrada

I love new ideas and features. I'll explore more on that

amitguptagwl avatar May 20 '20 12:05 amitguptagwl

@dkotrada have you tried using it? We are using it in our TypeScript library here.

svrooij avatar Sep 03 '20 20:09 svrooij

typing file already embedded. However, I'm not sure if it can be used in deno.

amitguptagwl avatar Sep 06 '20 06:09 amitguptagwl

is it ok if I send a PR to add support for deno using denoify?

sijad avatar Sep 28 '20 18:09 sijad

I don't have much idea of denoify. I hope it'll setup external to the code.

amitguptagwl avatar Sep 30 '20 02:09 amitguptagwl

it stated that files need to be converted to typescript:

If your module is vanilla JS it needs to be ported to TypeScript first. (1) (1) Don't be afraid, renaming your source with .ts and dropping some any here and there will do the trick. You will be able to pull it off even if you aren't familiar with typescript.

sijad avatar Sep 30 '20 06:09 sijad

I think the ts types are not correct for the XMLParser: grafik

TomlDev avatar Dec 08 '21 09:12 TomlDev

I can see no error related to removeNSPrefix

amitguptagwl avatar Dec 09 '21 01:12 amitguptagwl

Sorry, I was too dumb to copy 2 lines of code. I put the parserOptions in the wrong place and not in the constructor.

TomlDev avatar Dec 09 '21 07:12 TomlDev

I stumbled here. Since it's still open, it can be used in Deno via Skypack or soon with npm support. With Skypack like so:

import { XMLParser, (...) } from "https://cdn.skypack.dev/fast-xml-parser?dts";

It would still be nice to rewrite the code to run with Deno out of the box, and do everything with Deno tooling. I am already dual publishing to Deno and Node.js with dnt.

flevi29 avatar Aug 25 '22 16:08 flevi29

FYI TypeScript types have already been requested here: https://github.com/NaturalIntelligence/fast-xml-parser/issues/69 And provided there:

  • https://github.com/NaturalIntelligence/fast-xml-parser/pull/71
  • https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/package.json#L60

Lucas-C avatar Nov 03 '22 13:11 Lucas-C

If any Deno users end up here: The current release works perfectly well with Deno's npm support :tada:

soulchild avatar May 11 '23 11:05 soulchild

@soulchild Nope.

$ deno cache --unstable --reload --check=all --lock-write mod.ts
Check file:///.../my_project/mod.ts
error: TS2580 [ERROR]: Cannot find name 'Buffer'.
  parse(xmlData: string | Buffer ,validationOptions?: validationOptionsOptional | boolean): any;
                          ~~~~~~
    at file:///Users/deniz/Library/Caches/deno/npm/registry.npmjs.org/fast-xml-parser/4.2.2/src/fxp.d.ts:93:27

denizdogan avatar May 29 '23 08:05 denizdogan

@denizdogan Weird! I must admit that I just recently started using Deno and don't know what your deno CLI switches exactly do, but I'm using fast-xml-parser successfully like this:

deno.jsonc

{
  "imports": {
    "fast-xml-parser": "npm:fast-xml-parser@^4.2.2"
  }
}

main.ts

import { XMLParser } from 'fast-xml-parser';
const parser = new XMLParser();
deno run main.ts

soulchild avatar May 31 '23 14:05 soulchild

Ah, I see that deno --check=all type-checks everything, so indeed there seems to be some typing problem which I just didn't run into.

soulchild avatar May 31 '23 14:05 soulchild

I got this working by doing the following as suggested in the Deno docs:

/// <reference types="npm:@types/node" />
import { XMLParser } from 'fast-xml-parser';
const parser = new XMLParser();

Now, the following doesn't complain about the missing types for the Buffer Node.js built-in anymore:

deno run --check=all main.ts

soulchild avatar Jun 01 '23 06:06 soulchild