-
Notifications
You must be signed in to change notification settings - Fork 59
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
Typescript typings #25
Comments
Would be nice if you can crate typescript definitions, thanks for the offer Makarov. Can you create a pull request in https://github.com/DefinitelyTyped/DefinitelyTyped? |
This might be useful for anyone else: declare module "timesync" {
type TimeSync = {
destroy();
now(): number;
on(event: "change", callback: (offset: number) => void);
on(event: "error", callback: (err: any) => void);
on(event: "sync", callback: (value: "start" | "end") => void);
off(event: "change" | "error" | "sync", callback?: () => void);
sync();
send(to: string, data: object, timeout: number): Promise<void>;
receive(from: string, data: object);
};
type TimeSyncCreateOptions = {
interval?: number;
timeout?: number;
delay?: number;
repeat?: number;
peers?: string | string[];
server?: string;
now?: () => number;
};
function create(options: TimeSyncCreateOptions): TimeSync;
} |
To complete @dbachrach's response, I've added the server side typings as well: declare module "timesync" {
type TimeSync = {
destroy();
now(): number;
on(event: "change", callback: (offset: number) => void);
on(event: "error", callback: (err: any) => void);
on(event: "sync", callback: (value: "start" | "end") => void);
off(event: "change" | "error" | "sync", callback?: () => void);
sync();
send(to: string, data: object, timeout: number): Promise<void>;
receive(from: string, data: object);
};
type TimeSyncCreateOptions = {
interval?: number;
timeout?: number;
delay?: number;
repeat?: number;
peers?: string | string[];
server?: string;
now?: () => number;
};
function create(options: TimeSyncCreateOptions): TimeSync;
export = TimeSync;
}
declare module 'timesync/server' {
import type { Request as ExpressRequest, Response as ExpressResponse } from 'express';
import type { createServer as createHttpServer, Server } from 'http';
function requestHandler(req: Request | ExpressRequest, res: Response | ExpressResponse): void;
function createServer(): ReturnType<typeof createHttpServer>;
function attachServer(server: Server, path?: string): void;
} Could we implement this in a PR? We just need to add a {
"name": "timesync",
"typings": "./typings.d.ts",
...
} |
@rgolea I followed your steps but I can't get it to work for me. I'm trying to import for use with socket.io. I did:
at this point the import errors complaining about types goes away, but when I try to actually use the module with It seems like timesync is using the type declarations in typings.d.ts, but isn't using node_modules/timesync for the actual code. |
@nonotnoah I get the same issue. |
I took a different approach and refactored the whole source to TypeScript and configured |
Hi,
it would be great to have typescript types.
The text was updated successfully, but these errors were encountered: