Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some type errors in JavaScript #21452

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion files.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const info = {
"base1/test-locale.js",
"base1/test-location.js",
"base1/test-metrics.js",
"base1/test-no-jquery.js",
"base1/test-path.ts",
"base1/test-permissions.js",
"base1/test-promise.ts",
Expand Down
6 changes: 1 addition & 5 deletions pkg/apps/appstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ export function get_metainfo_db() {
debug("read metainfo_db:", metainfo_db);
}
})
.fail(function (error) {
if (error != "closed") {
console.warn(error);
}
});
.catch(error => console.warn("watch-appstream.py failed:", error));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

}

return metainfo_db;
Expand Down
29 changes: 0 additions & 29 deletions pkg/base1/test-no-jquery.js

This file was deleted.

14 changes: 14 additions & 0 deletions pkg/lib/cockpit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ declare module 'cockpit' {
changed(changes: { [property: string]: unknown }): void;
}

interface DBusProxiesEvents extends EventMap {
added(proxy: DBusProxy): void;
changed(proxy: DBusProxy): void;
removed(proxy: DBusProxy): void;
}

interface DBusProxy extends EventSource<DBusProxyEvents> {
valid: boolean;
[property: string]: unknown;
Expand All @@ -232,10 +238,18 @@ declare module 'cockpit' {
timeout?: number,
};

interface DBusProxies extends EventSource<DBusProxiesEvents> {
client: DBusClient;
iface: string;
path_namespace: string;
wait(callback?: () => void): Promise<void>;
}

interface DBusClient {
readonly unique_name: string;
readonly options: DBusOptions;
proxy(interface?: string, path?: string, options?: { watch?: boolean }): DBusProxy;
proxies(interface?: string, path_namespace?: string, options?: { watch?: boolean }): DBusProxies;
call(path: string, iface: string, method: string, args?: unknown[] | null, options?: DBusCallOptions): Promise<unknown[]>;
watch(path: string): DeferredPromise<void>,
close(): void;
Expand Down
26 changes: 14 additions & 12 deletions pkg/lib/cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1547,21 +1547,23 @@ function factory() {
const self = this;
event_mixin(self, { });

self.client = client;
self.iface = iface;
self.path_namespace = path_namespace;

let waits;

self.wait = function(func) {
if (func)
waits.always(func);
return waits;
Comment on lines +1556 to +1559
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 added lines are not executed by any test.

};

Object.defineProperties(self, {
client: { value: client, enumerable: false, writable: false },
iface: { value: iface, enumerable: false, writable: false },
path_namespace: { value: path_namespace, enumerable: false, writable: false },
wait: {
enumerable: false,
writable: false,
value: function(func) {
if (func)
waits.always(func);
return waits;
}
}
client: { enumerable: false, writable: false },
iface: { enumerable: false, writable: false },
path_namespace: { enumerable: false, writable: false },
wait: { enumerable: false, writable: false },
});

/* Subscribe to signals once for all proxies */
Expand Down
12 changes: 6 additions & 6 deletions pkg/lib/cockpit/_internal/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export function Channel(options) {
/* Now open the channel */
const command = { };
for (const i in options)
command[i] = options[i];
if (i !== "binary")
command[i] = options[i];
/* handle binary specially: Our JS API has always been boolean, while the wire protocol is
* a string with the only valid value "raw". */
if (binary)
command.binary = "raw";
command.command = "open";
command.channel = id;

Expand All @@ -112,11 +117,6 @@ export function Channel(options) {
command.host = transport_globals.default_host;
}

if (binary)
command.binary = "raw";
else
delete command.binary;

command["flow-control"] = true;
transport.send_control(command);

Expand Down
2 changes: 2 additions & 0 deletions pkg/shell/machines/machines.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Manifests } from "../manifests";

export function generate_connection_string(user: string | null, port: string | null, addr: string) : string;
export function split_connection_string (conn_to: string) : { address: string, user?: string, port?: number };
export function get_init_superuser_for_options (options: {[key: string]: string }) : string | null;
export function host_superuser_storage_key (host: string): string;

export interface Machine {
key: string;
Expand Down
1 change: 1 addition & 0 deletions pkg/storaged/crypto/keyslots.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function ensure_non_root_nbde_support(steps, progress, client, block) {
.then(() => ensure_crypto_option(steps, progress, client, block, "_netdev"));
}

/** @type (client: any, path: string) => boolean */
function contains_rootfs(client, path) {
const block = client.blocks[path];
const crypto = client.blocks_crypto[path];
Expand Down
12 changes: 7 additions & 5 deletions pkg/systemd/hwinfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ const SystemInfo = ({ info, onSecurityClick }) => {
);
};

let cachedMitigations;

function availableMitigations() {
if (availableMitigations.cachedMitigations !== undefined)
return Promise.resolve(availableMitigations.cachedMitigations);
if (cachedMitigations !== undefined)
return Promise.resolve(cachedMitigations);
/* nosmt */
const promises = [cockpit.spawn(["lscpu"], { environ: ["LC_ALL=C.UTF-8"], }), cockpit.file("/proc/cmdline").read()];
return Promise.all(promises).then(values => {
Expand All @@ -146,12 +148,12 @@ function availableMitigations() {
const nosmt_available = threads_per_core > 1 && (values[1].indexOf("nosmt=") === -1 || values[1].indexOf("nosmt=force") !== -1);
const mitigations_match = values[1].match(/\bmitigations=(\S*)\b/);

availableMitigations.cachedMitigations = {
cachedMitigations = {
available: nosmt_available,
nosmt_enabled,
mitigations_arg: mitigations_match ? mitigations_match[1] : undefined,
};
return availableMitigations.cachedMitigations;
return cachedMitigations;
});
}

Expand All @@ -172,7 +174,7 @@ const CPUSecurityMitigationsDialog = () => {
options = ['set', 'nosmt'];
} else {
// this may either be an argument of its own, or part of mitigations=
const ma = availableMitigations.cachedMitigations.mitigations_arg;
const ma = cachedMitigations.mitigations_arg;
if (ma && ma.indexOf("nosmt") >= 0) {
const new_args = ma.split(',').filter(opt => opt != 'nosmt');
options = ['set', 'mitigations=' + new_args.join(',')];
Expand Down
8 changes: 7 additions & 1 deletion pkg/systemd/services.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,13 @@ const ServicesPageFilters = ({
const onDeleteChipGroup = (typeLabel) => {
const type = getFilterLabelKey(typeLabel);

setFilters({ ...filters, [type]: [] });
if (type)
setFilters({ ...filters, [type]: [] });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

else
setFilters({
activeState: [],
fileState: []
Comment on lines +796 to +798
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 added lines are not executed by any test.

});
};

const onClearAllFilters = useCallback(() => {
Expand Down
8 changes: 0 additions & 8 deletions test/common/typecheck
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ ignored_codes = [
"TS7005", # Variable '*' implicitly has an 'any[]' type.
"TS7006", # Parameter '*' implicitly has an 'any' type.
"TS7008", # Member '*' implicitly has an 'any[]' type.
"TS7009", # 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to remove this here as well. The problem is not the implicit "any", but that TS missed that something is a constructor, which is worth fixing even in relaxed code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, with that new approach we can and should fix similar instances

"TS7010", # '*', which lacks return-type annotation, implicitly has an 'any' return type.
"TS7015", # Element implicitly has an 'any' type because index expression is not of type '*'.
"TS7016", # Could not find a declaration file for module '*'...
Expand All @@ -72,13 +71,11 @@ javascript_ignored_codes = [
"TS7005", # Variable '*' implicitly has an 'any[]' type.
"TS7006", # Parameter '*' implicitly has an 'any' type.
"TS7008", # Member '*' implicitly has an 'any[]' type.
"TS7009", # 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
"TS7015", # Element implicitly has an 'any' type because index expression is not of type '*'.
"TS7016", # Could not find a declaration file for module '*'...
"TS7019", # Rest parameter '*' implicitly has an 'any[]' type
"TS7022", # '*' implicitly has type 'any'...
"TS7023", # '*' implicitly has return type 'any' because ...
"TS7024", # Function implicitly has return type 'any' because ...
"TS7031", # Binding element '*' implicitly has an 'any' type.
"TS7034", # Variable '*' implicitly has type 'any' in some locations where its type cannot be determined.
"TS7053", # Element implicitly has an 'any' type because expression of type 'any' can't be used to
Expand All @@ -99,15 +96,10 @@ javascript_ignored_codes = [
"TS2741", # Property 'X' is missing in type
"TS2551", # Property 'X' does not exist on type
"TS2304", # Cannot find name 'X'
"TS2581", # Cannot find name '$'. Do you need to install type definitions for jQuery?
"TS2305", # Module '"./machines/machines"' has no exported member 'get_init_superuser_for_options'.
"TS2790", # The operand of a 'delete' operator must be optional.
"TS2367", # This comparison appears to be unintentional because the types 'Error' and 'string' have no overlap.
"TS2538", # Type 'null' cannot be used as an index type.
"TS2559", # Type 'never[]' has no properties in common with type 'DBusCallOptions'.
"TS2769", # No overload matches this call.
"TS2739", # Type '{ title: string; value: string; }' is missing the following properties from type
"TS2464", # A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
"TS2488", # Type 'X' must have a '[Symbol.iterator]()' method that returns an iterator.
"TS2349", # This expression is not callable.
"TS2554", # Expected 0 arguments, but got 1.
Expand Down
Loading