Add types for saslmechanisms

This commit is contained in:
Dimitri Benin
2018-11-27 00:14:08 +01:00
parent 3fd74d83b5
commit 009260118e
4 changed files with 77 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for saslmechanisms 0.1
// Project: https://github.com/jaredhanson/js-sasl
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = Factory;
declare class Factory {
static Factory: typeof Factory;
use(name: string, mechanism: Factory.MechanismStatic): this;
use(mechanism: Factory.MechanismStatic): this;
create(mechanisms: string[]): Factory.Mechanism | null;
}
declare namespace Factory {
interface MechanismStatic {
new (): Mechanism;
prototype: {
[key: string]: any;
name: string;
};
}
interface Mechanism {
name: string;
response(cred: { [key: string]: any }): string;
challenge(chal: string): void;
}
}
@@ -0,0 +1,22 @@
import Fct = require('saslmechanisms');
import { Factory, MechanismStatic, Mechanism } from 'saslmechanisms';
const Mech: MechanismStatic = null as any;
const factory = new Fct();
new Factory();
new Factory.Factory();
// $ExpectType Factory
factory.use(Mech);
factory.use('Mech', Mech);
const mech: Mechanism | null = factory.create(['Mech']);
if (mech) {
// $ExpectType string
mech.name;
// $ExpectType string
mech.response({ foo: 'bar' });
// $ExpectType void
mech.challenge('challenge');
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"saslmechanisms-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }