Skip to content

Commit

Permalink
style: make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Aug 10, 2020
1 parent 65c6eb9 commit c5a1761
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
rules: {
// unused vars will be handles by the TS compiler
'@typescript-eslint/no-unused-vars': 'off',
},
};
3 changes: 3 additions & 0 deletions src/tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async function disposeExistingTestingServers() {
await testingServers.gqlServer?.dispose();
if (testingServers.httpServer) {
await new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
testingServers.httpServer!.close((err) => {
if (err) {
return reject(err);
Expand Down Expand Up @@ -101,7 +102,9 @@ async function makeServer(options: Partial<ServerOptions> = {}) {
},
);
return new Promise<Server>((resolve) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
testingServers.httpServer!.listen(port, () =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
resolve(testingServers.gqlServer!),
),
);
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Disposable {
dispose: () => Promise<void>;
}

export interface Sink<T = any> {
export interface Sink<T = unknown> {
next(value: T): void;
error(error: Error): void;
complete(): void;
Expand Down
35 changes: 19 additions & 16 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
*
*/

export function isObject(val: unknown): val is object {
export function isObject(val: unknown): val is Record<PropertyKey, unknown> {
return typeof val === 'object' && val !== null;
}

export function hasOwnProperty<O extends object, P extends PropertyKey>(
obj: O,
prop: P,
): obj is O & Record<P, unknown> {
return obj.hasOwnProperty(prop);
export function hasOwnProperty<
O extends Record<PropertyKey, unknown>,
P extends PropertyKey
>(obj: O, prop: P): obj is O & Record<P, unknown> {
return Object.prototype.hasOwnProperty.call(obj, prop);
}

export function hasOwnObjectProperty<O extends object, P extends PropertyKey>(
obj: O,
prop: P,
): obj is O & Record<P, object> {
return obj.hasOwnProperty(prop) && isObject((obj as any)[prop]);
export function hasOwnObjectProperty<
O extends Record<PropertyKey, unknown>,
P extends PropertyKey
>(obj: O, prop: P): obj is O & Record<P, Record<PropertyKey, unknown>> {
return Object.prototype.hasOwnProperty.call(obj, prop) && isObject(obj[prop]);
}

export function hasOwnStringProperty<O extends object, P extends PropertyKey>(
obj: O,
prop: P,
): obj is O & Record<P, string> {
return obj.hasOwnProperty(prop) && typeof (obj as any)[prop] === 'string';
export function hasOwnStringProperty<
O extends Record<PropertyKey, unknown>,
P extends PropertyKey
>(obj: O, prop: P): obj is O & Record<P, string> {
return (
Object.prototype.hasOwnProperty.call(obj, prop) &&
typeof obj[prop] === 'string'
);
}

0 comments on commit c5a1761

Please sign in to comment.