Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Typescript types declaration file (.d.ts) #38

Open
PassiDel opened this issue Nov 12, 2023 · 1 comment
Open

add Typescript types declaration file (.d.ts) #38

PassiDel opened this issue Nov 12, 2023 · 1 comment

Comments

@PassiDel
Copy link

Hey, thank you for your client!

I would like to use it for a TS-based project, but unfortunately since there are no published types, the typescript server throws errors. As a local fix, I manually added a flightradar24-client.d.ts file. Of course, it would be nicer if the types were recognised automatically.

Would you be willing to convert this client to TS or would you accept a PR that does this? As an interim solution, it would also be possible to add this .d.ts file manually, which could look something like this:

{
        "name": "flightradar24-client",
	"files": [
		"index.js",
		"lib"
	],
+	"typings": "types.d.ts",
	"keywords": [
		"aviation",
		"airplanes",
		"flights",
		"flightradar24"
	]
}
// types.d.ts
declare module 'flightradar24-client' {
  function fetchFlight(flight: string): Promise<{
    id: string | null;
    callsign: string | null;
    liveData: boolean;
    model: string | null;
    registration: string | null;
    airline: string | null;
    origin: {
      id: string | null;
      name: string | null;
      coordinates: {
        latitude: number | null;
        longitude: number | null;
        altitude: number | null;
      };
      timezone: string | null;
      country: string | null;
    };
    destination: {
      id: string | null;
      name: string | null;
      coordinates: {
        latitude: number | null;
        longitude: number | null;
        altitude: number | null;
      };
      timezone: string | null;
      country: string | null;
    };
    departure: string | null;
    scheduledDeparture: string | null;
    departureTerminal: string | null;
    departureGate: string | null;
    arrival: string | null;
    scheduledArrival: string | null;
    arrivalTerminal: string | null;
    arrivalGate: string | null;
    delay: number | null;
  }>;

  function fetchFromRadar(
    north: number,
    west: number,
    south: number,
    east: number,
    when?: number,
    opt?: Partial<{
      FAA: boolean;
      FLARM: boolean;
      MLAT: boolean;
      ADSB: boolean;
      inAir: boolean;
      onGround: boolean;
      inactive: boolean;
      gliders: boolean;
      estimatedPositions: boolean;
    }>
  ): Promise<
    {
      id: string;
      registration: string | null;
      flight: string | null;
      callsign: string | null;
      origin: string | null;
      destination: string | null;
      latitude: number;
      longitude: number;
      altitude: number;
      bearing: number;
      speed: number | null;
      rateOfClimb: number;
      isOnGround: boolean;
      squawkCode: string;
      model: string | null;
      modeSCode: string | null;
      radar: string;
      isGlider: boolean;
      timestamp: number | null;
    }[]
  >;
}
@derhuerst
Copy link
Owner

Would you be willing to convert this client to TS […]?

No, sorry. Using TypeScript is not worth the hassle for me.

As an interim solution, it would also be possible to add this .d.ts file manually, which could look something like this:

I would merge a "shallow" type declaration file that merely specifies the returned objects (the objects the returned Promise resolves with, to be exact) as-is, without specifying all entries.
Otherwise, I know for sure that I would modify index.js without thinking about index.d.ts, and a wrong type declaration file is worse than a vague one.

@derhuerst derhuerst changed the title Typescript Support add Typescript types declaration file (.d.ts) Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants