So I have a library written in TypeScript, which uses the NPM depenedency 'ldapjs'.
I also have @types/ldapjs
installed into my project.
So in my project, I have this:
import {Client} from '@types/ldapjs';
import * as ldap from 'ldapjs';
Now here is my question - how can I add properties to a client with type Client?
I have this:
export interface IClient extends Client{
__inactiveTimeout: Timer,
returnToPool: Function,
ldapPoolRemoved?: boolean
}
where IClient is my version of an ldapjs Client with a few extra properties.
let client = ldap.createClient(this.connOpts); // => Client
client.cdtClientId = this.clientId++;
but the problem is, if I try to add properties to client, I get this error:
'cdtClientId' property does not exist on type Client.
Is there some way I can cast Client to IClient?
How can I do this? I have this same problem in many different projects.
While what you have added as answer might solve your problem, you can directly augment the Client
interface and add the properties. You don't even need IClient
. You can use module augmentation:
declare module "ldapjs" {
interface Client {
// Your additional properties here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With