-
Notifications
You must be signed in to change notification settings - Fork 129
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 Definition #95
Comments
I've just started working on this, so far I've covered enough for my very small use case of just getting the UID from a generic card. I don't really know the technicalities of all the card types neither do I know the inner workings of I've added the types in a way in which no source code is modified, and the definitions in Reader.d.ts should be easy to work with and extend. My fork is here. To test the types you can add Not sure if you got resources to work on this right now @pokusew, but I'd be willing to help :) |
Thanks vaaski for sharing your types!
Can someone assist? |
I wonder if this will work: declare module 'nfc-pcsc' {
import { EventEmitter } from 'events';
interface NfcPcsc extends EventEmitter {
start(): Promise<void>;
stop(): Promise<void>;
listDevices(): Promise<string[]>;
open(device: string): Promise<void>;
close(): Promise<void>;
transmit(data: Buffer): Promise<Buffer>;
}
function nfc(): NfcPcsc;
export = nfc;
} |
I didn't write it all down, but it looks like this. nfc-pcsc.d.ts declare module 'nfc-pcsc' {
export type ListenerSignature<L> = {
[E in keyof L]: (...args: any[]) => any;
};
export type DefaultListener = {
[k: string]: (...args: any[]) => any;
};
export class TypedEmitter<L extends ListenerSignature<L> = DefaultListener> {
static defaultMaxListeners: number;
addListener<U extends keyof L>(event: U, listener: L[U]): this;
prependListener<U extends keyof L>(event: U, listener: L[U]): this;
prependOnceListener<U extends keyof L>(event: U, listener: L[U]): this;
removeListener<U extends keyof L>(event: U, listener: L[U]): this;
removeAllListeners(event?: keyof L): this;
once<U extends keyof L>(event: U, listener: L[U]): this;
on<U extends keyof L>(event: U, listener: L[U]): this;
off<U extends keyof L>(event: U, listener: L[U]): this;
emit<U extends keyof L>(event: U, ...args: Parameters<L[U]>): boolean;
eventNames<U extends keyof L>(): U[];
listenerCount(type: keyof L): number;
listeners<U extends keyof L>(type: U): L[U][];
rawListeners<U extends keyof L>(type: U): L[U][];
getMaxListeners(): number;
setMaxListeners(n: number): this;
}
type Type = 'TAG_ISO_14443_3' | 'TAG_ISO_14443_4';
const KEY_TYPE_A = 0x60;
const KEY_TYPE_B = 0x61;
interface Card {
type: Type;
standard: Type;
uid?: string;
data?: Buffer;
}
interface ReaderEmitter {
card: (x: Card) => void;
'card.off': (x: Card) => void;
error: (x: Error) => void;
end: () => void;
}
export class Reader extends TypedEmitter<ReaderEmitter> {
get name(): string;
authenticate(blockNumber: number, keyType: number, key: string, obsolete?: boolean): Promise<boolean>;
read(
blockNumber: number,
length: number,
blockSize?: number,
packetSize?: number,
readClass?: number
): Promise<Buffer>;
}
interface NFCEmitter {
reader: (reader: Reader) => void;
error: (error: Error) => void;
}
export class NFC extends TypedEmitter<NFCEmitter> {}
} |
Hi, I'm trying to use this library in typescript project but got error
Could not find a declaration file for module 'nfc-pcsc'
Could you please add typescript definition to this awesome library. thanks.
The text was updated successfully, but these errors were encountered: