chore: switch on eslint rule: @typescript-eslint/no-explicit-any

This commit is contained in:
Sándor Levcsák 2020-11-11 00:02:48 +02:00
parent 7c2d0a9df3
commit 668e7dac73
9 changed files with 26 additions and 25 deletions

View File

@ -81,9 +81,7 @@
"comma-dangle": [
"warn",
"always-multiline"
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
]
}
},
"jest": {

View File

@ -81,7 +81,7 @@ export function useArticles () {
export type ArticlesType = 'global-feed' | 'my-feed' | 'tag-feed' | 'user-feed' | 'user-favorites-feed'
export const articlesTypes: ArticlesType[] = ['global-feed', 'my-feed', 'tag-feed', 'user-feed', 'user-favorites-feed']
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
export const isArticlesType = (type: any): type is ArticlesType => articlesTypes.includes(type)
const routeNameToArticlesType: Partial<Record<AppRouteNames, ArticlesType>> = ({

View File

@ -14,7 +14,7 @@ export async function postFavoriteArticle (slug: string): Promise<Either<Authori
}
export async function deleteFavoriteArticle (slug: string): Promise<Either<AuthorizationError, Article>> {
const result1 = await request.checkableDelete(`/articles/${slug}/favorite`)
const result1 = await request.checkableDelete<ArticleResponse>(`/articles/${slug}/favorite`)
const result2 = mapAuthorizationResponse<ArticleResponse>(result1)
if (result2.isOk()) return success(result2.value.article)

View File

@ -1,6 +1,6 @@
import { request } from '../index'
export async function deleteComment (slug: string, commentId: number): Promise<any> {
export async function deleteComment (slug: string, commentId: number): Promise<Record<string, unknown>> {
return request.delete(`/articles/${slug}/comments/${commentId}`)
}

View File

@ -1,10 +1,12 @@
import { Ref, ref } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
interface CreateAsyncProcessReturn<T extends (...args: any[]) => any> {
active: Ref<boolean>
run: (...args : Parameters<T>) => Promise<ReturnType<T>>
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function createAsyncProcess<T extends (...args: any[]) => any> (fn: T): CreateAsyncProcessReturn<T> {
const active: CreateAsyncProcessReturn<T>['active'] = ref(false)

View File

@ -1,4 +1,4 @@
import FetchRequest from 'src/utils/request'
import FetchRequest, { FetchRequestOptions } from 'src/utils/request'
import { Either, fail, isEither, success } from 'src/utils/either'
import params2query from 'src/utils/params-to-query'
@ -38,7 +38,7 @@ function isCheckable (method: CheckableMethod | Method): method is CheckableMeth
return ['checkableGet', 'checkableDelete', 'checkablePost', 'checkablePut', 'checkablePatch'].includes(method)
}
async function triggerMethod<T = any> (request: FetchRequest, method: Method | CheckableMethod, options?: any): Promise<T | Either<NetworkError, T>> {
async function triggerMethod<T = unknown> (request: FetchRequest, method: Method | CheckableMethod, options?: Partial<FetchRequestOptions>): Promise<T | Either<NetworkError, T>> {
if (isCheckable(method)) {
let response: Either<NetworkError, T>
if (isCheckableSafe(method)) response = await request[method]<T>(PATH, options)

View File

@ -5,7 +5,7 @@ import { NetworkError } from '../types/error'
import { Either, fail, success } from './either'
import params2query from './params-to-query'
interface FetchRequestOptions {
export interface FetchRequestOptions {
prefix: string;
headers: Record<string, string>;
params: Record<string, string | number | boolean>;
@ -57,62 +57,63 @@ export default class FetchRequest {
private runFetch ({ method, url, data, options }: {
method: 'GET' | 'DELETE' | 'POST' | 'PUT' | 'PATCH',
url: string,
data?: Record<string, any>,
options: Partial<FetchRequestOptions>
data?: unknown,
options?: Partial<FetchRequestOptions>
}) {
const finalUrl = this.generateFinalUrl(url, options)
const headers = this.generateFinalHeaders(options)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fetchOptions: any = { method, headers }
if (data) fetchOptions.body = JSON.stringify(data)
return fetch(finalUrl, fetchOptions)
}
private runSafeFetch (method: 'GET' | 'DELETE', url: string, options: Partial<FetchRequestOptions>) {
private runSafeFetch (method: 'GET' | 'DELETE', url: string, options?: Partial<FetchRequestOptions>) {
return this.runFetch({ method, url, options })
}
private runUnsafeFetch (method: 'POST' | 'PUT' | 'PATCH', url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
private runUnsafeFetch (method: 'POST' | 'PUT' | 'PATCH', url: string, data?: unknown, options?: Partial<FetchRequestOptions>) {
return this.runFetch({ method, url, options, data })
}
get<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<T> {
get<T = unknown> (url: string, options?: Partial<FetchRequestOptions>): Promise<T> {
return this.runSafeFetch('GET', url, options).then(r => this.handleCorrectResponse<T>(r))
}
checkableGet<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
checkableGet<T = unknown> (url: string, options?: Partial<FetchRequestOptions>): Promise<Either<NetworkError, T>> {
return this.runSafeFetch('GET', url, options).then(r => this.handleResponse<T>(r))
}
post<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<T> {
post<T = unknown> (url: string, data?: unknown, options?: Partial<FetchRequestOptions>): Promise<T> {
return this.runUnsafeFetch('POST', url, data, options).then(r => this.handleCorrectResponse<T>(r))
}
checkablePost<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
checkablePost<T = unknown> (url: string, data?: unknown, options?: Partial<FetchRequestOptions>): Promise<Either<NetworkError, T>> {
return this.runUnsafeFetch('POST', url, data, options).then(r => this.handleResponse<T>(r))
}
delete<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<T> {
delete<T = unknown> (url: string, options?: Partial<FetchRequestOptions>): Promise<T> {
return this.runSafeFetch('DELETE', url, options).then(r => this.handleCorrectResponse<T>(r))
}
checkableDelete<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
checkableDelete<T = unknown> (url: string, options?: Partial<FetchRequestOptions>): Promise<Either<NetworkError, T>> {
return this.runSafeFetch('DELETE', url, options).then(r => this.handleResponse<T>(r))
}
put<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<T> {
put<T = unknown> (url: string, data?: unknown, options?: Partial<FetchRequestOptions>): Promise<T> {
return this.runUnsafeFetch('PUT', url, data, options).then(r => this.handleCorrectResponse<T>(r))
}
checkablePut<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
checkablePut<T> (url: string, data?: unknown, options?: Partial<FetchRequestOptions>): Promise<Either<NetworkError, T>> {
return this.runUnsafeFetch('PUT', url, data, options).then(r => this.handleResponse<T>(r))
}
patch<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<T> {
patch<T = unknown> (url: string, data?: unknown, options?: Partial<FetchRequestOptions>): Promise<T> {
return this.runUnsafeFetch('PATCH', url, data, options).then(r => this.handleCorrectResponse<T>(r))
}
checkablePatch<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
checkablePatch<T> (url: string, data?: unknown, options?: Partial<FetchRequestOptions>): Promise<Either<NetworkError, T>> {
return this.runUnsafeFetch('PATCH', url, data, options).then(r => this.handleResponse<T>(r))
}

View File

@ -1,4 +1,4 @@
function get<T = any> (key: string): T | null {
function get<T> (key: string): T | null {
try {
const value = localStorage.getItem(key) || ''
return JSON.parse(value)

View File

@ -6,7 +6,7 @@ interface FetchResponseFull {
ok: boolean,
status: number,
statusText:string
json: (...args: any) => Promise<any>
json: () => Promise<unknown>
}
export default function mockFetch (data: FetchResponseBody | FetchResponseFull): void {