Skip to content

Commit

Permalink
chore: add more explicit types (#4018)
Browse files Browse the repository at this point in the history
* Add explicit types

* Format.

* Revert
  • Loading branch information
dsherret authored Dec 22, 2023
1 parent fd31167 commit ceb107f
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bytes/last_index_of_needle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export function lastIndexOfNeedle(
source: Uint8Array,
needle: Uint8Array,
start = source.length - 1,
start: number = source.length - 1,
): number {
if (start < 0) {
return -1;
Expand Down
6 changes: 3 additions & 3 deletions http/unstable_cookie_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const keys = Symbol("#keys");
const requestHeaders = Symbol("#requestHeaders");
const responseHeaders = Symbol("#responseHeaders");
const isSecure = Symbol("#secure");
const requestKeys = Symbol("#requestKeys");
const requestKeys: unique symbol = Symbol("#requestKeys");

/** An internal abstract class which provides common functionality for
* {@link CookieMap} and {@link SecureCookieMap}.
Expand Down Expand Up @@ -417,7 +417,7 @@ abstract class CookieMapBase implements Mergeable {
return init;
}

[Symbol.for("Deno.customInspect")]() {
[Symbol.for("Deno.customInspect")](): string {
return `${this.constructor.name} []`;
}

Expand All @@ -426,7 +426,7 @@ abstract class CookieMapBase implements Mergeable {
// deno-lint-ignore no-explicit-any
options: any,
inspect: (value: unknown, options?: unknown) => string,
) {
): string {
if (depth < 0) {
return options.stylize(`[${this.constructor.name}]`, "special");
}
Expand Down
2 changes: 1 addition & 1 deletion io/slice_long_to_bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
export function sliceLongToBytes(
d: number,
dest = Array.from<number>({ length: 8 }),
dest: number[] = Array.from<number>({ length: 8 }),
): number[] {
let big = BigInt(d);
for (let i = 0; i < 8; i++) {
Expand Down
2 changes: 1 addition & 1 deletion log/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class FileHandler extends WriterHandler {
protected _filename: string;
protected _mode: LogMode;
protected _openOptions: Deno.OpenOptions;
protected _encoder = new TextEncoder();
protected _encoder: TextEncoder = new TextEncoder();
#unloadCallback = (() => {
this.destroy();
}).bind(this);
Expand Down
6 changes: 4 additions & 2 deletions log/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
*/

import { Logger } from "./logger.ts";
import type { GenericFunction } from "./logger.ts";
import type { GenericFunction, LogRecord } from "./logger.ts";
import {
BaseHandler,
ConsoleHandler,
Expand Down Expand Up @@ -439,7 +439,9 @@ export const handlers = {
RotatingFileHandler,
};

export const formatters = {
export const formatters: {
jsonFormatter(logRecord: LogRecord): string;
} = {
jsonFormatter,
};

Expand Down
2 changes: 1 addition & 1 deletion path/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ import { SEP } from "./separator.ts";
* console.log(p); // "./deno/std/"
* ```
*/
export function common(paths: string[], sep = SEP): string {
export function common(paths: string[], sep: typeof SEP = SEP): string {
return _common(paths, sep);
}
2 changes: 1 addition & 1 deletion path/posix/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ import { SEP } from "./separator.ts";
* console.log(p); // "./deno/std/"
* ```
*/
export function common(paths: string[], sep = SEP): string {
export function common(paths: string[], sep: typeof SEP = SEP): string {
return _common(paths, sep);
}
2 changes: 1 addition & 1 deletion path/windows/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ import { SEP } from "./separator.ts";
* console.log(p); // "./deno/std/"
* ```
*/
export function common(paths: string[], sep = SEP): string {
export function common(paths: string[], sep: typeof SEP = SEP): string {
return _common(paths, sep);
}
2 changes: 1 addition & 1 deletion streams/byte_slice_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ByteSliceStream extends TransformStream<Uint8Array, Uint8Array> {
#offsetEnd = 0;

/** Constructs a new instance. */
constructor(start = 0, end = Infinity) {
constructor(start = 0, end: number = Infinity) {
super({
start: () => {
assert(start >= 0, "`start` must be greater than 0");
Expand Down
2 changes: 1 addition & 1 deletion yaml/schema/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { json } from "./json.ts";

// Standard YAML's Core schema.
// http://www.yaml.org/spec/1.2/spec.html#id2804923
export const core = new Schema({
export const core: Schema = new Schema({
include: [json],
});
2 changes: 1 addition & 1 deletion yaml/schema/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { core } from "./core.ts";

// JS-YAML's default schema for `safeLoad` function.
// It is not described in the YAML specification.
export const def = new Schema({
export const def: Schema = new Schema({
explicit: [binary, omap, pairs, set],
implicit: [timestamp, merge],
include: [core],
Expand Down
2 changes: 1 addition & 1 deletion yaml/schema/extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { def } from "./default.ts";
* );
* ```
*/
export const extended = new Schema({
export const extended: Schema = new Schema({
explicit: [regexp, undefinedType],
include: [def],
});
2 changes: 1 addition & 1 deletion yaml/schema/failsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { map, seq, str } from "../_type/mod.ts";

// Standard YAML's Failsafe schema.
// http://www.yaml.org/spec/1.2/spec.html#id2802346
export const failsafe = new Schema({
export const failsafe: Schema = new Schema({
explicit: [str, seq, map],
});
2 changes: 1 addition & 1 deletion yaml/schema/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { failsafe } from "./failsafe.ts";

// Standard YAML's JSON schema.
// http://www.yaml.org/spec/1.2/spec.html#id2803231
export const json = new Schema({
export const json: Schema = new Schema({
implicit: [nil, bool, int, float],
include: [failsafe],
});

0 comments on commit ceb107f

Please sign in to comment.