Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// $ExpectType true
constant(true)(undefined);
// $ExpectType false
constant(false)(undefined);
// $ExpectType 0
constant(0)(undefined);
// $ExpectType "const"
constant("const")(undefined);
// $ExpectType undefined
constant(undefined)(undefined);
// $ExpectType null
constant(null)(undefined);
// $ExpectType string[]
array(string)(undefined);
// $ExpectType { [key: string]: string; }
dict(string)(undefined);
// $ExpectType string
record(() => "")(undefined);
// $ExpectType { a: string; }
record(field => ({ a: field("a", string) }))(undefined);
// $ExpectType string
tuple(() => "")(undefined);
// $ExpectType string[]
tuple(item => [item(0, string)])(undefined);
// $ExpectType [string]
tuple<[string]>(item => [item(0, string)])(undefined);
// $ExpectType [string, boolean]
pair(string, boolean)(undefined);
// $ExpectType [string, boolean, boolean]
triple(string, boolean, boolean)(undefined);
// $ExpectType {}
autoRecord<{}>({})(undefined);
array(string, "throw");
array(string, "skip");
array(string, { default: "" });
array(string, { default: [1] });
// Wrong mode:
// $ExpectError
array(string, "nope");
dict(string);
dict(string, "throw");
dict(string, "skip");
dict(string, { default: "" });
dict(string, { default: [1] });
// Wrong mode:
// $ExpectError
dict(string, "nope");
// Accidentally passed an object instead of a callback:
record({
// $ExpectError
a: string,
});
record(field => field("", string));
record(field => field("", string, "throw"));
record(field => field("", string, { default: "" }));
record(field => field("", string, { default: null }));
// Wrong key type:
// $ExpectError
record(field => field(0, string));
// Wrong order:
// $ExpectError
record(field => field(string, ""));
// $ExpectError
constant({ type: "user" });
// Accidentally passed a decoder:
// $ExpectError
constant(string);
array(string);
array(string, "throw");
array(string, "skip");
array(string, { default: "" });
array(string, { default: [1] });
// Wrong mode:
// $ExpectError
array(string, "nope");
dict(string);
dict(string, "throw");
dict(string, "skip");
dict(string, { default: "" });
dict(string, { default: [1] });
// Wrong mode:
// $ExpectError
dict(string, "nope");
// Accidentally passed an object instead of a callback:
record({
// $ExpectError
a: string,
});
record(field => field("", string));
record(field => field("", string, "throw"));
record(field => field("", string, { default: "" }));
constant({ type: "user" });
// Accidentally passed a decoder:
// $ExpectError
constant(string);
array(string);
array(string, "throw");
array(string, "skip");
array(string, { default: "" });
array(string, { default: [1] });
// Wrong mode:
// $ExpectError
array(string, "nope");
dict(string);
dict(string, "throw");
dict(string, "skip");
dict(string, { default: "" });
dict(string, { default: [1] });
// Wrong mode:
// $ExpectError
dict(string, "nope");
// Accidentally passed an object instead of a callback:
record({
// $ExpectError
a: string,
});
record(field => field("", string));
record(field => field("", string, "throw"));
record(field => field("", string, { default: "" }));
record(field => field("", string, { default: null }));
// Accidentally passed a decoder:
// $ExpectError
constant(string);
array(string);
array(string, "throw");
array(string, "skip");
array(string, { default: "" });
array(string, { default: [1] });
// Wrong mode:
// $ExpectError
array(string, "nope");
dict(string);
dict(string, "throw");
dict(string, "skip");
dict(string, { default: "" });
dict(string, { default: [1] });
// Wrong mode:
// $ExpectError
dict(string, "nope");
// Accidentally passed an object instead of a callback:
record({
// $ExpectError
a: string,
});
record(field => field("", string));
record(field => field("", string, "throw"));
record(field => field("", string, { default: "" }));
record(field => field("", string, { default: null }));
// Wrong key type:
renderDurations: Durations,
}>;
export const decodePerf: Decoder = array(
autoRecord({
timeToFirstPaint: number,
timeToLastPaint: number,
topDurations: decodeDurations,
collectStats: array(decodeStats),
renderDurations: decodeDurations,
})
);
export type TabsPerf = { [tabId: string]: Perf, ... };
export const decodeTabsPerf: Decoder = dict(decodePerf);
export class TimeTracker {
_durations: Durations = [];
_current: ?{ label: string, timestamp: number } = undefined;
start(label: string) {
this.stop();
this._current = {
label,
timestamp: Date.now(),
};
}
stop() {
const current = this._current;
autoActivate: field("autoActivate", boolean, {
default: defaults.autoActivate,
}),
overTypingDuration: field("overTypingDuration", decodeUnsignedInt, {
default: defaults.overTypingDuration,
}),
css: field("css", string, {
default: defaults.css,
}),
logLevel: field("logLevel", map(string, decodeLogLevel), {
default: defaults.logLevel,
}),
useKeyTranslations: field("useKeyTranslations", boolean, {
default: defaults.useKeyTranslations,
}),
keyTranslations: field("keyTranslations", dict(decodeKeyPair, "skip"), {
default: defaults.keyTranslations,
}),
normalKeyboardShortcuts: field(
"normalKeyboardShortcuts",
array(decodeKeyboardMappingWithModifiers, "skip"),
{ default: defaults.normalKeyboardShortcuts }
),
hintsKeyboardShortcuts: field(
"hintsKeyboardShortcuts",
array(decodeKeyboardMapping, "skip"),
{ default: defaults.hintsKeyboardShortcuts }
),
}));
}