Reverse engineering https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/hapi-auth-bearer-token/index.d.ts and can’t figure out the following line.
declare var BearerToken: Plugin<{}>;
Reverse engineering https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/hapi-auth-bearer-token/index.d.ts and can’t figure out the following line.
declare var BearerToken: Plugin<{}>;
this means BearerToken variable is of type plugin which holds objects inside
let fruits: Array<string> = ['Apple', 'Orange', 'Banana'];
Plugin<{}>
means Plugin
is a generic type with a single type parameter, which is {}
in this case.
{}
is the empty object literal type (like { someProperty: SomeType }
, but with no properties defined). It isn't the same as object
, though:
const message: {} = 'hello world';
compiles (I am not sure why), but
const message: object = 'hello world';
doesn't.
(I also somehow can't find documentation for this form of types in TypeScript Handbook, but they are used in examples there, e.g. let { a, b }: { a: string, b: number } = o;
or type Alias = { num: number }
.)
EDIT: const message: { length: number } = 'hello world';
compiles (which makes sense) and { length: number }
is a subtype of {}
.
In general Plugin
could be a generic class, generic interface or just array which only accepts objects. In the code Plugin
comes from Hapi
as per the import statement
import {
Request,
Plugin,
ResponseToolkit,
AuthenticationData,
} from 'hapi';
I did a quick search and found the documentation for hapi plugins. I hope this helps