Finish up no-unsafe-assignment fixes in azurecore (#22836)

* Finish up no-unsafe-assignment fixes in azurecore

* Add link to typings

* Remove unused

* Ignore webpack file
This commit is contained in:
Charles Gagnon
2023-04-24 14:13:00 -07:00
committed by GitHub
parent 8616c5948b
commit 167ef2fea8
5 changed files with 32 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
**/extensions/**/*.d.ts
**/extensions/**/build/**
**/extensions/**/colorize-fixtures/**
**/extensions/azurecore/extension.webpack.config.js
**/extensions/css-language-features/server/test/pathCompletionFixtures/**
**/extensions/html-language-features/server/lib/jquery.d.ts
**/extensions/html-language-features/server/src/test/pathCompletionFixtures/**

View File

@@ -11,6 +11,7 @@
}
],
// Disabled until the issues can be fixed
"@typescript-eslint/explicit-function-return-type": ["off"]
"@typescript-eslint/explicit-function-return-type": ["off"],
"@typescript-eslint/no-unsafe-assignment": "error"
}
}

View File

@@ -29,6 +29,7 @@ import { HttpClient } from './httpClient';
import { getProxyEnabledHttpClient, getTenantIgnoreList, updateTenantIgnoreList } from '../../utils';
import { errorToPromptFailedResult } from './networkUtils';
import { MsalCachePluginProvider } from '../utils/msalCachePlugin';
import { AzureListOperationResponse, ErrorResponseBodyWithError, isErrorResponseBody as isErrorResponseBodyWithError } from '../../azureResource/utils';
const localize = nls.loadMessageBundle();
export abstract class AzureAuth implements vscode.Disposable {
@@ -482,7 +483,7 @@ export abstract class AzureAuth implements vscode.Disposable {
Logger.verbose(`Fetching tenants with uri: ${tenantUri}`);
let tenantList: string[] = [];
const tenantResponse = await this.httpClient.sendGetRequestAsync<any>(tenantUri, {
const tenantResponse = await this.httpClient.sendGetRequestAsync<AzureListOperationResponse<TenantResponse[]> | ErrorResponseBodyWithError>(tenantUri, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
@@ -490,9 +491,9 @@ export abstract class AzureAuth implements vscode.Disposable {
});
const data = tenantResponse.data;
if (data.error) {
Logger.error(`Error fetching tenants :${data.error.code} - ${data.error.message}`);
throw new Error(`${data.error.code} - ${data.error.message}`);
if (isErrorResponseBodyWithError(data)) {
Logger.error(`Error fetching tenants :${data.error?.code} - ${data.error?.message}`);
throw new Error(`${data.error?.code} - ${data.error?.message}`);
}
const tenants: Tenant[] = data.value.map((tenantInfo: TenantResponse) => {
if (tenantInfo.displayName) {

View File

@@ -233,10 +233,14 @@ const networkRequestViaProxy = <T>(
// check if the value of the header is supposed to be a JSON object
try {
// TODO: Investigate this - https://github.com/microsoft/azuredatastudio/issues/22835
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const object = JSON.parse(headerValue);
// if it is, then convert it from a string to a JSON object
if (object && (typeof object === 'object')) {
// TODO: Investigate this - https://github.com/microsoft/azuredatastudio/issues/22835
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
headerValue = object;
}
} catch (e) {

View File

@@ -20,14 +20,33 @@ import * as Constants from '../constants';
import { getProxyEnabledHttpClient } from '../utils';
import { HttpClient } from '../account-provider/auths/httpClient';
import { NetworkRequestOptions } from '@azure/msal-common';
import { ErrorResponseBody } from '@azure/arm-subscriptions/esm/models';
const localize = nls.loadMessageBundle();
/**
* Specialized version of the ErrorResponseBody that is required to have the error
* information for easier typing support, without it how do we know it's an error
* response?
* https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/subscription/arm-subscriptions/src/models/index.ts#L180
*/
export type ErrorResponseBodyWithError = Required<ErrorResponseBody>;
/**
* Checks if the body object given is an error response, that is has a non-undefined
* property named error which contains detailed about the error.
* @param body The body object to check
* @returns True if the body is an ErrorResponseBodyWithError
*/
export function isErrorResponseBody(body: any): body is ErrorResponseBodyWithError {
return 'error' in body && body.error;
}
/**
* Shape of list operation responses
* e.g. https://learn.microsoft.com/en-us/rest/api/storagerp/srp_json_list_operations#response-body
*/
declare type AzureListOperationResponse<T> = {
export declare type AzureListOperationResponse<T> = {
value: T;
}