I’m working on a NestJS project that integrates with Active Directory using the ldapts library. I encountered a TypeScript error when trying to set certain attributes in my Active Directory service.
The errors are as follows:
[01:01:16] File change detected. Starting incremental compilation...
src/oracle-hrms/services/active-directory.service.ts:77:11 - error TS2353: Object literal may only specify known properties, and 'userAccountControl' does not exist in type 'Attribute'.
77 userAccountControl: '514', // Adjust this value based on your AD setup
~~~~~~~~~~~~~~~~~~
node_modules/ldapts/dist/index.d.ts:785:5
785 modification: Attribute;
~~~~~~~~~~~~
The expected type comes from property 'modification' which is declared here on type 'ChangeOptions'
src/oracle-hrms/services/active-directory.service.ts:107:13 - error TS2353: Object literal may only specify known properties, and 'sn' does not exist in type 'Attribute'.
107 sn: accountData.sn,
~~
node_modules/ldapts/dist/index.d.ts:785:5
785 modification: Attribute;
~~~~~~~~~~~~
The expected type comes from property 'modification' which is declared here on type 'ChangeOptions'
src/oracle-hrms/services/active-directory.service.ts:113:13 - error TS2353: Object literal may only specify known properties, and 'mail' does not exist in type 'Attribute'.
113 mail: accountData.mail,
~~~~
node_modules/ldapts/dist/index.d.ts:785:5
785 modification: Attribute;
~~~~~~~~~~~~
The expected type comes from property 'modification' which is declared here on type 'ChangeOptions'
src/oracle-hrms/services/active-directory.service.ts:150:13 - error TS2353: Object literal may only specify known properties, and 'member' does not exist in type 'Attribute'.
150 member: userDN,
~~~~~~
node_modules/ldapts/dist/index.d.ts:785:5
785 modification: Attribute;
~~~~~~~~~~~~
The expected type comes from property 'modification' which is declared here on type 'ChangeOptions'
[01:01:16] Found 4 errors. Watching for file changes.
// In src/oracle-hrms/services/active-directory.service.ts
// Error at line 77
await this.ldapClient.modify(dn, [
{
operation: 'replace',
modification: {
userAccountControl: '514', // Adjust this value based on your AD setup
},
},
]);
// Error at line 107
await this.ldapClient.modify(dn, [
{
operation: 'replace',
modification: {
sn: accountData.sn,
},
},
]);
// Error at line 113
await this.ldapClient.modify(dn, [
{
operation: 'replace',
modification: {
mail: accountData.mail,
},
},
]);
// Error at line 150
await this.ldapClient.modify(dn, [
{
operation: 'add',
modification: {
member: userDN,
},
},
]);
It appears that userAccountControl, sn, mail, and member are not recognized as valid properties of the Attribute type defined in ldapts.
What I have tried:
Ensuring the attributes are correctly named and exist in AD.
Checking the ldapts documentation and type definitions.
Environment:
NestJS version: 8.0.0
ldapts version: 3.0.0
TypeScript version: 4.3.5
Questions:
How can I correctly specify these attributes in the modification object?
Is there a way to extend or modify the Attribute type definition to include these properties?
Are there any alternative approaches to setting these AD attributes using ldapts?