From 2440cce7ac47f8046e93faacfd60c75396b01115 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Fri, 18 Oct 2019 15:50:21 +0100 Subject: [PATCH] Uprade TypeScript from 3.2.2 to 3.6.4 --- package.json | 2 +- src/helpers/index.ts | 4 +--- src/index.ts | 17 ++++++++++++----- yarn.lock | 8 ++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index ac360c9..3c8543d 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/helpers/index.ts b/src/helpers/index.ts index ac2f835..dce184d 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,5 +1,3 @@ -const tuple = >(...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 = (obj: O) => Object.keys(obj) as Array; @@ -7,7 +5,7 @@ const keys = (obj: O) => Object.keys(obj) as Array; // `Object.entries` is ES2017, but this lib only supports ES2015 at runtime, so we must define our // own version. const entries = (obj: Record) => - keys(obj).map(key => tuple(key, obj[key])); + keys(obj).map(key => [key, obj[key]] as const); const fromEntries = (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; diff --git a/src/index.ts b/src/index.ts index 120c00a..61e989d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,18 +62,25 @@ export type ImgixUrlQueryParams = { faceindex?: number; facepad?: number; }; - -const pickTrueInObject = (obj: Record): Partial> => - pickBy(obj, (_key, value): value is true => value); +// TODO: remove cast and either make all functions allow partial, or all non-partial. +// const pickTrueInObject = (obj: Record) => +const pickTrueInObject = ( + obj: Partial>, +): Partial> => + pickBy(obj as Record, (_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, ); diff --git a/yarn.lock b/yarn.lock index e7c8c40..2c9906c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"