🤖 Merge PR #50993 [avocat] add initial types by @timcosta

This commit is contained in:
Tim Costa
2021-02-03 20:06:21 -05:00
committed by GitHub
parent ccd86f078e
commit f7e8926356
5 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import * as Avocat from 'avocat';
import * as Boom from '@hapi/boom';
const notFound: Boom.Boom = Avocat.rethrow(Boom.notFound(), { return: true });
notFound.message;
Avocat.rethrow(Boom.badImplementation(), { includeMessage: true });
try {
Avocat.rethrow(Boom.conflict());
} catch (e) {}

19
types/avocat/index.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// Type definitions for avocat 2.0
// Project: https://github.com/hapipal/avocat#readme
// Definitions by: Tim Costa <https://github.com/timcosta>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { ResponseObject } from '@hapi/hapi';
import { Boom } from '@hapi/boom';
export interface Options {
return?: boolean;
includeMessage?: boolean;
}
// the return type has to be any because the following scenarios exist:
// 1. options.return = false - this will always throw or return false
// 2. options.return = true - this will either return false or a Boom type
// Due to scenario 2 and that behavior changes based on options, a return
// type of any is the only way I see this working
export function rethrow(err: ResponseObject | Boom, options?: Options): any;

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"@hapi/boom": "^9.1.1"
}
}

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@hapi/*": [ "hapi__*" ]
}
},
"files": [
"index.d.ts",
"avocat-tests.ts"
]
}

1
types/avocat/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }