kensnyder / any-date-parser

Parse a wide range of date formats including human-input dates
ISC License
32 stars 6 forks source link

Wrong Typescript exports #33

Open jhmen opened 10 months ago

jhmen commented 10 months ago

Hi, I have tried to import the Parser and format classes. But I'm getting an error that the any-date-parser package does not export the classes. I think that in the index.d.ts file, the exports in the declare module "any-date-parser" section are missing.

Used import Syntax: import { Parser, Format } from 'any-date-parser'; Error: Vue: Module  'any-date-parser'  has no exported member  Parser

I think this might be a solution:

declare module "any-date-parser" {
    export default parser;
    export = { Parser, Format };
    const parser: Parser;
    import Parser = require("src/Parser/Parser");
    import Format = require("src/Format/Format");
}

But I don't know if this is best practice

mohsentaleb commented 6 months ago

I can also confirm the faulty typescript declarations.

NanderTGA commented 3 months ago

There are multiple ways to tackle this issue:

  1. Use the typeof operator
  2. Import the classes from those files directly

These typings aren't faulty at all. BTW, using the export = syntax, you can only have a default export and nothing else. This is probably why the developer didn't export those classes.

uhrb commented 3 months ago

Faulty as hell. Type definitions are not good at all. I cannot import dayMonthYear for example, since typing defines location "src/formats/dayMonthYear/dayMonthYear" but this location is absolute, not relative to the module, so cannot be resolved on compile time.

NanderTGA commented 3 months ago

Yeah I agree now