Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Uprade TypeScript from 3.2.2 to 3.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverJAsh committed Oct 18, 2019
1 parent 993e0a8 commit 2440cce
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"tslint": "^5.11.0",
"tslint-language-service": "^0.9.9",
"tslint-no-unused": "^0.2.0-alpha.1",
"typescript": "^3.2.2"
"typescript": "^3.6.4"
}
}
4 changes: 1 addition & 3 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const tuple = <T extends Array<unknown>>(...args: T): T => args;

// `Object.keys` does not return the keys as string literals, only strings. Use this helper as a
// workaround. https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208
const keys = <O extends object>(obj: O) => Object.keys(obj) as Array<keyof O>;

// `Object.entries` is ES2017, but this lib only supports ES2015 at runtime, so we must define our
// own version.
const entries = <K extends string, V>(obj: Record<K, V>) =>
keys(obj).map(key => tuple(key, obj[key]));
keys(obj).map(key => [key, obj[key]] as const);
const fromEntries = <K extends string, V>(arr: Array<[K, V]>) =>
// `Object.assign` is poorly typed: it returns `any` when spreading. Use cast to workaround.
Object.assign({}, ...arr.map(([k, v]) => ({ [k]: v }))) as Record<K, V>;
Expand Down
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,25 @@ export type ImgixUrlQueryParams = {
faceindex?: number;
facepad?: number;
};

const pickTrueInObject = <K extends string>(obj: Record<K, boolean>): Partial<Record<K, true>> =>
pickBy(obj, (_key, value): value is true => value);
// TODO: remove cast and either make all functions allow partial, or all non-partial.
// const pickTrueInObject = <K extends string>(obj: Record<K, boolean>) =>
const pickTrueInObject = <K extends string>(
obj: Partial<Record<K, boolean>>,
): Partial<Record<K, true>> =>
pickBy(obj as Record<K, boolean>, (_key, value): value is true => value);
const pickTrueObjectKeys = pipe(
pickTrueInObject,
// tslint:disable-next-line no-unbound-method
Object.keys,
// This function has an overload which breaks type inference. See:
// https://github.com/Microsoft/TypeScript/issues/29904#issuecomment-471105473. We workaround this
// by wrapping the function.
obj => Object.keys(obj),
);
const undefinedIfEmptyString = (str: string): string | undefined => (str === '' ? undefined : str);
const joinWithComma = (strs: string[]) => strs.join(',');
const serializeImgixUrlQueryParamListValue = pipe(
pickTrueObjectKeys,
// Needed to workaround https://github.com/microsoft/TypeScript/issues/29904#issuecomment-543785534
value => value,
joinWithComma,
undefinedIfEmptyString,
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ tsutils@^2.27.2:
dependencies:
tslib "^1.8.1"

typescript@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==
typescript@^3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==

url-transformers@^0.0.5:
version "0.0.5"
Expand Down

0 comments on commit 2440cce

Please sign in to comment.