Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: placate TypeScript 4.4 #809

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sdk-rtl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@looker/sdk-rtl",
"version": "21.0.19",
"version": "21.0.20",
AprilArcus marked this conversation as resolved.
Show resolved Hide resolved
"description": "Looker SDK Runtime Library",
"main": "lib/index.js",
"module": "lib/esm/index.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk-rtl/src/browserTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
responseMode,
ResponseMode,
safeBase64,
isErrorLike,
} from './transport'
import { BaseTransport } from './baseTransport'
import { ICryptoHash } from './cryptoHash'
Expand Down Expand Up @@ -297,7 +298,8 @@ export class BrowserTransport extends BaseTransport {
res
)
return result
} catch (e) {
} catch (e: unknown) {
if (!isErrorLike(e)) throw e
const error: ISDKError = {
message:
typeof e.message === 'string'
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk-rtl/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,18 @@ export function safeBase64(u8: Uint8Array) {
const rawBase64 = btoa(String.fromCharCode(...u8))
return rawBase64.replace(/\+/g, '-').replace(/\//g, '_')
}

/**
* Type predicate. Asserts that a given object is error-like.
* @param error a value of unknown type
* @return boolean true if the error has a `message` key of type string.
*/
export function isErrorLike<T extends unknown>(
error: T
): error is T & { message: string } {
if (typeof error !== 'object') return false
if (!error) return false
if (!Object.prototype.hasOwnProperty.call(error, 'message')) return false
if (typeof (error as { message: unknown }).message !== 'string') return false
return true
}