Skip to content

Commit c5253e0

Browse files
authored
[Communication] - Linter - Fixing some linter warnings in the common package (Azure#13874)
* [Lint] fixing warnings * [Lint] fixing warnings * [Linter] fixing the types as per PR feedback
1 parent b31dd7c commit c5253e0

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

sdk/communication/communication-common/review/communication-common.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const getIdentifierKind: (identifier: CommunicationIdentifier) => Communi
6969
export const isCommunicationUserIdentifier: (identifier: CommunicationIdentifier) => identifier is CommunicationUserIdentifier;
7070

7171
// @public
72-
export const isKeyCredential: (credential: any) => credential is KeyCredential;
72+
export const isKeyCredential: (credential: unknown) => credential is KeyCredential;
7373

7474
// @public
7575
export const isMicrosoftTeamsUserIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftTeamsUserIdentifier;
@@ -93,7 +93,7 @@ export interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
9393
}
9494

9595
// @public
96-
export const parseClientArguments: (connectionStringOrUrl: string, credentialOrOptions?: any) => UrlWithCredential;
96+
export const parseClientArguments: (connectionStringOrUrl: string, credentialOrOptions?: unknown) => UrlWithCredential;
9797

9898
// @public
9999
export const parseConnectionString: (connectionString: string) => EndpointCredential;

sdk/communication/communication-common/src/credential/clientArguments.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ const assertValidEndpoint = (host: string): void => {
2727
*
2828
* @param credential - The credential being checked.
2929
*/
30-
export const isKeyCredential = (credential: any): credential is KeyCredential => {
31-
return credential && typeof credential.key === "string" && credential.getToken === undefined;
30+
export const isKeyCredential = (credential: unknown): credential is KeyCredential => {
31+
const castCredential = credential as {
32+
key: unknown;
33+
getToken: unknown;
34+
};
35+
return (
36+
castCredential &&
37+
typeof castCredential.key === "string" &&
38+
castCredential.getToken === undefined
39+
);
3240
};
3341

3442
/**
@@ -44,7 +52,7 @@ export type UrlWithCredential = {
4452
*/
4553
export const parseClientArguments = (
4654
connectionStringOrUrl: string,
47-
credentialOrOptions?: any
55+
credentialOrOptions?: unknown
4856
): UrlWithCredential => {
4957
if (isKeyCredential(credentialOrOptions) || isTokenCredential(credentialOrOptions)) {
5058
assertValidEndpoint(connectionStringOrUrl);

sdk/communication/communication-common/src/identifierModelSerializer.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,37 @@ export interface _SerializedMicrosoftTeamsUserIdentifier {
7777
*/
7878
export type _SerializedCommunicationCloudEnvironment = "public" | "dod" | "gcch";
7979

80+
const addRawIdIfExisting = <T>(
81+
identifier: T,
82+
rawId: string | undefined
83+
): T & { rawId?: string } => {
84+
return rawId === undefined ? identifier : { ...identifier, rawId: rawId };
85+
};
86+
87+
const assertNotNullOrUndefined = <
88+
T extends Record<string, unknown>,
89+
P extends keyof T,
90+
Q extends keyof T[P]
91+
>(
92+
obj: T,
93+
prop: Q
94+
): Required<Required<T>[P]>[Q] => {
95+
const subObjName = Object.keys(obj)[0];
96+
const subObj = (obj as any)[subObjName];
97+
if (prop in subObj) {
98+
return subObj[prop];
99+
}
100+
throw new Error(`Property ${prop} is required for identifier of type ${subObjName}.`);
101+
};
102+
103+
const assertMaximumOneNestedModel = (identifier: _SerializedCommunicationIdentifier): void => {
104+
const { rawId, ...props } = identifier;
105+
const keys = Object.keys(props);
106+
if (keys.length > 1) {
107+
throw new Error(`Only one of the properties in ${JSON.stringify(keys)} should be present.`);
108+
}
109+
};
110+
80111
/**
81112
* @internal
82113
* Translates a CommunicationIdentifier to its serialized format for sending a request.
@@ -150,30 +181,3 @@ export const _deserializeCommunicationIdentifier = (
150181
id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, "rawId")
151182
};
152183
};
153-
154-
const addRawIdIfExisting = <T>(
155-
identifier: T,
156-
rawId: string | undefined
157-
): T & { rawId?: string } => {
158-
return rawId === undefined ? identifier : { ...identifier, rawId: rawId };
159-
};
160-
161-
const assertNotNullOrUndefined = <T extends {}, P extends keyof T, Q extends keyof T[P]>(
162-
obj: T,
163-
prop: Q
164-
): Required<Required<T>[P]>[Q] => {
165-
const subObjName = Object.keys(obj)[0];
166-
const subObj = (obj as any)[subObjName];
167-
if (prop in subObj) {
168-
return subObj[prop];
169-
}
170-
throw new Error(`Property ${prop} is required for identifier of type ${subObjName}.`);
171-
};
172-
173-
const assertMaximumOneNestedModel = (identifier: _SerializedCommunicationIdentifier) => {
174-
const { rawId, ...props } = identifier;
175-
const keys = Object.keys(props);
176-
if (keys.length > 1) {
177-
throw new Error(`Only one of the properties in ${JSON.stringify(keys)} should be present.`);
178-
}
179-
};

sdk/communication/communication-common/test/identifierModelSerializer.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ const assertThrowsMissingProperty = <
3131
serializedIdentifier: _SerializedCommunicationIdentifier,
3232
identifierType: P,
3333
missingPropertyName: Q
34-
) => {
34+
): void => {
3535
assert.throws(() => {
3636
_deserializeCommunicationIdentifier(serializedIdentifier);
3737
}, `Property ${missingPropertyName} is required for identifier of type ${identifierType}.`);
3838
};
3939

4040
const assertThrowsTooManyProperties = (
4141
serializedIdentifier: _SerializedCommunicationIdentifier
42-
) => {
42+
): void => {
4343
const { rawId, ...props } = serializedIdentifier;
4444
assert.throws(() => {
4545
_deserializeCommunicationIdentifier(serializedIdentifier);

0 commit comments

Comments
 (0)