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

feat(schemas)!: improve TS array types #26172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lint/fixer/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export const removeIrrelevantFlags = (
if (result.length == 1) {
return result[0];
}
return result;
return result as [
SimpleSupportStatement,
SimpleSupportStatement,
...SimpleSupportStatement[],
];
};

/**
Expand Down
12 changes: 6 additions & 6 deletions schemas/compat-data.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"items": {
"$ref": "#/definitions/flag_statement"
},
"tsType": "FlagStatement[]"
"tsType": "[FlagStatement, ...FlagStatement[]]"
},
"impl_url": {
"anyOf": [
Expand All @@ -76,7 +76,7 @@
}
],
"description": "An optional changeset/commit URL for the revision which implemented the feature in the source code, or the URL to the bug tracking the implementation, for the associated browser.",
"tsType": "string | string[]",
"tsType": "string | [string, string, ...string[]]",
"errorMessage": {
"pattern": "impl_url must be a link to a browser commit or bug URL. URLs must be in shortened form (ex. bugs.chromium.org -> crbug.com). Note: `npm run fix` may resolve these issues."
}
Expand All @@ -99,7 +99,7 @@
}
}
],
"tsType": "string | string[]"
"tsType": "string | [string, string, ...string[]]"
}
},
"required": ["version_added"],
Expand Down Expand Up @@ -147,7 +147,7 @@
},
{ "const": "mirror" }
],
"tsType": "SimpleSupportStatement | SimpleSupportStatement[]"
"tsType": "SimpleSupportStatement | [SimpleSupportStatement, SimpleSupportStatement, ...SimpleSupportStatement[]]"
},

"status_block": {
Expand Down Expand Up @@ -237,13 +237,13 @@
}
],
"description": "An optional URL or array of URLs, each of which is for a specific part of a specification in which this feature is defined. Each URL must contain a fragment identifier.",
"tsType": "string | string[]"
"tsType": "string | [string, string, ...string[]]"
},
"tags": {
"description": "An optional array of strings allowing to assign tags to the feature.",
"type": "array",
"minItems": 1,
"tsType": "string[]"
"tsType": "[string, ...string[]]"
},
"source_file": {
"type": "string",
Expand Down
8 changes: 6 additions & 2 deletions scripts/build/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { InternalSupportBlock } from '../../types/index.js';

const { browsers } = bcd;

type Notes = string | string[] | null;
type Notes = string | [string, string, ...string[]] | null;

/**
*/
Expand Down Expand Up @@ -204,7 +204,11 @@ export const bumpSupport = (
return newData[0];

default:
return newData;
return newData as [
SimpleSupportStatement,
SimpleSupportStatement,
...SimpleSupportStatement[],
];
}
}

Expand Down
6 changes: 5 additions & 1 deletion scripts/migrations/002-remove-webview-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export const removeWebViewFlags = (
} else if (result.length == 1) {
value.support.webview_android = result[0];
} else {
value.support.webview_android = result;
value.support.webview_android = result as [
SimpleSupportStatement,
SimpleSupportStatement,
...SimpleSupportStatement[],
];
}
} else if (value.support.webview_android.flags !== undefined) {
value.support.webview_android = { version_added: false };
Expand Down
11 changes: 9 additions & 2 deletions scripts/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import esMain from 'es-main';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import { BrowserName, Identifier } from '../types/types.js';
import {
BrowserName,
Identifier,
SimpleSupportStatement,
} from '../types/types.js';
import { InternalSupportStatement } from '../types/index.js';
import dataFolders from '../scripts/lib/data-folders.js';
import bcd from '../index.js';
Expand Down Expand Up @@ -68,7 +72,10 @@ export function* iterateFeatures(
continue;
}
for (const browser of browsers) {
let browserData = comp[browser];
let browserData:
| SimpleSupportStatement
| SimpleSupportStatement[]
| undefined = comp[browser];

if (!browserData) {
if (values.length == 0 || values.includes('null')) {
Expand Down