fast-xml-parser
fast-xml-parser copied to clipboard
Feature request: TypeScript Support
Could you please provide TypeScript support? In particular https://deno.land/
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.
You can watch the repo for new changes or star it.
Already starred it. 👍
I love new ideas and features. I'll explore more on that
@dkotrada have you tried using it? We are using it in our TypeScript library here.
typing file already embedded. However, I'm not sure if it can be used in deno.
is it ok if I send a PR to add support for deno using denoify?
I don't have much idea of denoify. I hope it'll setup external to the code.
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.
I think the ts types are not correct for the XMLParser:
I can see no error related to removeNSPrefix
Sorry, I was too dumb to copy 2 lines of code. I put the parserOptions in the wrong place and not in the constructor.
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.
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
If any Deno users end up here: The current release works perfectly well with Deno's npm support :tada:
@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 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
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.
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