Skip to content

Commit

Permalink
chore: updates TS to fix ci errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelik committed Nov 13, 2023
1 parent 79962ec commit 5316d6d
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 31 deletions.
2 changes: 1 addition & 1 deletion addon/utils/mung-options-for-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function mungOptionsForFetch(

for (const key in options) {
if (Object.prototype.hasOwnProperty.call(options, key)) {
fetchOptions[key] = options[key];
(fetchOptions as any)[key] = (options as any)[key];
}
}

Expand Down
36 changes: 36 additions & 0 deletions errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Checks if the given response represents an unauthorized request error
*/
export declare function isUnauthorizedResponse(response: Response): boolean;
/**
* Checks if the given response represents a forbidden request error
*/
export declare function isForbiddenResponse(response: Response): boolean;
/**
* Checks if the given response represents an invalid request error
*/
export declare function isInvalidResponse(response: Response): boolean;
/**
* Checks if the given response represents a bad request error
*/
export declare function isBadRequestResponse(response: Response): boolean;
/**
* Checks if the given response represents a "not found" error
*/
export declare function isNotFoundResponse(response: Response): boolean;
/**
* Checks if the given response represents a "gone" error
*/
export declare function isGoneResponse(response: Response): boolean;
/**
* Checks if the given error is an "abort" error
*/
export declare function isAbortError(error: DOMException): boolean;
/**
* Checks if the given response represents a conflict error
*/
export declare function isConflictResponse(response: Response): boolean;
/**
* Checks if the given response represents a server error
*/
export declare function isServerErrorResponse(response: Response): boolean;
44 changes: 35 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test": "ember test",
"test:node": "ember ts:precompile && mocha && ember ts:clean",
"test:node": "yarn prepack && mocha && yarn postpack",
"test:all": "yarn run test:node && ember try:each",
"prepublishOnly": "ember ts:precompile",
"postpublish": "ember ts:clean"
"prepack": "ember ts:precompile",
"postpack": "ember ts:clean"
},
"dependencies": {
"abortcontroller-polyfill": "^1.7.3",
Expand All @@ -42,7 +42,7 @@
"caniuse-api": "^3.0.0",
"ember-cli-babel": "^7.26.11",
"ember-cli-htmlbars": "^6.2.0",
"ember-cli-typescript": "^4.1.0",
"ember-cli-typescript": "^5.2.1",
"ember-cli-version-checker": "^5.1.2",
"node-fetch": "^2.6.1",
"whatwg-fetch": "^3.6.2"
Expand All @@ -56,10 +56,35 @@
"@embroider/test-setup": "^2.1.1",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@types/ember": "^4.0.8",
"@types/ember-data": "^4.4.0",
"@types/qunit": "^2.11.1",
"@types/rsvp": "^4.0.3",
"@tsconfig/ember": "^3.0.2",
"@types/ember": "^4.0.9",
"@types/ember-data": "^4.4.14",
"@types/ember-data__adapter": "^4.0.5",
"@types/ember-data__model": "^4.0.4",
"@types/ember-data__serializer": "^4.0.5",
"@types/ember-data__store": "^4.0.6",
"@types/ember-qunit": "^6.1.1",
"@types/ember-resolver": "^9.0.0",
"@types/ember__application": "^4.0.10",
"@types/ember__array": "^4.0.8",
"@types/ember__component": "^4.0.20",
"@types/ember__controller": "^4.0.10",
"@types/ember__debug": "^4.0.7",
"@types/ember__destroyable": "^4.0.4",
"@types/ember__engine": "^4.0.9",
"@types/ember__error": "^4.0.5",
"@types/ember__object": "^4.0.10",
"@types/ember__polyfills": "^4.0.5",
"@types/ember__routing": "^4.0.18",
"@types/ember__runloop": "^4.0.8",
"@types/ember__service": "^4.0.7",
"@types/ember__string": "^3.0.13",
"@types/ember__template": "^4.0.5",
"@types/ember__test": "^4.0.5",
"@types/ember-test-helpers": "^1.0.0",
"@types/ember__utils": "^4.0.6",
"@types/qunit": "^2.19.8",
"@types/rsvp": "^4.0.7",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"babel-eslint": "^10.0.2",
Expand Down Expand Up @@ -92,6 +117,7 @@
"eslint-plugin-qunit": "^7.3.4",
"fs-extra": "^9.0.1",
"glob": "^7.1.7",
"jquery": "^3.7.1",
"lerna-changelog": "^1.0.1",
"loader.js": "^4.2.3",
"mocha": "^8.4.0",
Expand All @@ -104,7 +130,7 @@
"stylelint": "^15.4.0",
"stylelint-config-standard": "^32.0.0",
"stylelint-prettier": "^3.0.0",
"typescript": "^5.0.0",
"typescript": "^5.2.2",
"webpack": "^5.78.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"noEmit": true,
"strictFunctionTypes": true,
"pretty": true,
"skipLibCheck": true,
"stripInternal": true,
"strict": true,
"inlineSourceMap": true,
Expand Down
22 changes: 22 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Mix from '@ember/polyfills/types';
export type Nullable<T> = T | null | undefined;
export type PlainObject<T = string | number | boolean> = {
[key: string]: T | PlainObject<T> | PlainObject<T>[] | undefined | null;
};
export type PlainHeaders = {
[key: string]: string;
};
export type Method = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
export type AjaxOptions = {
url: string;
type: Method;
data?: PlainObject | BodyInit;
headers?: PlainHeaders;
};
export type Credentials = 'omit' | 'same-origin' | 'include';
export type FetchOptions = Mix<AjaxOptions, {
body?: BodyInit | null;
method?: Method;
credentials: Credentials;
}>;
export declare function isPlainObject(obj: any): obj is PlainObject;
7 changes: 7 additions & 0 deletions utils/determine-body-promise.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="jquery" />
/**
* Function that always attempts to parse the response as json, and if an error is thrown,
* returns `undefined` if the response is successful and has a status code of 204 (No Content),
* or 205 (Reset Content) or if the request method was 'HEAD', and the plain payload otherwise.
*/
export default function determineBodyPromise(response: Response, requestData: JQueryAjaxSettings): Promise<object | string | undefined>;
5 changes: 5 additions & 0 deletions utils/mung-options-for-fetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FetchOptions, AjaxOptions } from 'ember-fetch/types';
/**
* Helper function that translates the options passed to `jQuery.ajax` into a format that `fetch` expects.
*/
export default function mungOptionsForFetch(options: AjaxOptions): FetchOptions;
6 changes: 6 additions & 0 deletions utils/serialize-query-params.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Helper function that turns the data/body of a request into a query param string.
* This is directly copied from jQuery.param.
*/
export declare function serializeQueryParams(queryParamsObject: object | string): string;
export default serializeQueryParams;
Loading

0 comments on commit 5316d6d

Please sign in to comment.