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

Upgrade to TypeScript 3.5 #5556

Merged
merged 1 commit into from Mar 31, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 44 additions & 11 deletions lib/Accessibility.js
Expand Up @@ -329,7 +329,9 @@ class AXNode {
role: this._role
};

/** @type {!Array<keyof SerializedAXNode>} */
/** @enum {'name'|'value'|'description'|'keyshortcuts'|'roledescription'|'valuetext'} */
let UserStringProperties; // eslint-disable-line no-unused-vars
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to do this without the need for the let and the eslint comment? (I'm no TypeScript expert...)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if this actually works, but it is worth a try:

/** @enum {string} */
const UserStringProperties = {
  Name: 'name',
  Value: 'value',
  ...
}

Then you can do Object.values(UserStringProperties) instead of the userStringProperties array down below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried this but it unfortunately doesn't work, because when you do for foo in Object.values(UserStringProperties) TypeScript only knows that foo is a string; it loses the fact that it was actually one of UserStringProperties, which causes problems. So I think this is the nicest way for now :(

/** @type {!Array<UserStringProperties>} */
const userStringProperties = [
'name',
'value',
Expand All @@ -338,13 +340,21 @@ class AXNode {
'roledescription',
'valuetext',
];
/**
* @param {UserStringProperties} key
*/
const getUserStringPropertyValue = key => /** @type string */(properties.get(key));

for (const userStringProperty of userStringProperties) {
if (!properties.has(userStringProperty))
continue;
node[userStringProperty] = properties.get(userStringProperty);

node[userStringProperty] = getUserStringPropertyValue(userStringProperty);
}

/** @type {!Array<keyof SerializedAXNode>} */
/** @enum {'disabled'|'expanded'|'focused'|'modal'|'multiline'|'multiselectable'|'readonly'|'required'|'selected'} */
let BooleanProperties; // eslint-disable-line no-unused-vars
/** @type {!Array<BooleanProperties>} */
const booleanProperties = [
'disabled',
'expanded',
Expand All @@ -356,18 +366,25 @@ class AXNode {
'required',
'selected',
];
/**
* @param {BooleanProperties} key
*/
const getBooleanPropertyValue = key => /** @type boolean */(properties.get(key));

for (const booleanProperty of booleanProperties) {
// WebArea's treat focus differently than other nodes. They report whether their frame has focus,
// not whether focus is specifically on the root node.
if (booleanProperty === 'focused' && this._role === 'WebArea')
continue;
const value = properties.get(booleanProperty);
const value = getBooleanPropertyValue(booleanProperty);
if (!value)
continue;
node[booleanProperty] = value;
node[booleanProperty] = getBooleanPropertyValue(booleanProperty);
}

/** @type {!Array<keyof SerializedAXNode>} */
/** @enum {'checked'|'pressed'} */
let TristateProperties; // eslint-disable-line no-unused-vars
/** @type {!Array<TristateProperties>} */
const tristateProperties = [
'checked',
'pressed',
Expand All @@ -378,29 +395,45 @@ class AXNode {
const value = properties.get(tristateProperty);
node[tristateProperty] = value === 'mixed' ? 'mixed' : value === 'true' ? true : false;
}
/** @type {!Array<keyof SerializedAXNode>} */


/** @enum {'level'|'valuemax'|'valuemin'} */
let NumericalProperties; // eslint-disable-line no-unused-vars
/** @type {!Array<NumericalProperties>} */
const numericalProperties = [
'level',
'valuemax',
'valuemin',
];
/**
* @param {NumericalProperties} key
*/
const getNumericalPropertyValue = key => /** @type number */(properties.get(key));
for (const numericalProperty of numericalProperties) {
if (!properties.has(numericalProperty))
continue;
node[numericalProperty] = properties.get(numericalProperty);
node[numericalProperty] = getNumericalPropertyValue(numericalProperty);
}
/** @type {!Array<keyof SerializedAXNode>} */


/** @enum {'autocomplete'|'haspopup'|'invalid'|'orientation'} */
let TokenProperties; // eslint-disable-line no-unused-vars
/** @type {!Array<TokenProperties>} */
const tokenProperties = [
'autocomplete',
'haspopup',
'invalid',
'orientation',
];
/**
* @param {TokenProperties} key
*/
const getTokenPropertyValue = key => /** @type string */(properties.get(key));
for (const tokenProperty of tokenProperties) {
const value = properties.get(tokenProperty);
const value = getTokenPropertyValue(tokenProperty);
if (!value || value === 'false')
continue;
node[tokenProperty] = value;
node[tokenProperty] = getTokenPropertyValue(tokenProperty);
}
return node;
}
Expand Down
13 changes: 9 additions & 4 deletions lib/Page.js
Expand Up @@ -444,8 +444,10 @@ class Page extends EventEmitter {
await Promise.all(this.frames().map(frame => frame.evaluate(expression).catch(debugError)));

function addPageBinding(bindingName) {
const binding = window[bindingName];
window[bindingName] = (...args) => {
const win = /** @type * */ (window);
const binding = /** @type function(string):* */ (win[bindingName]);

win[bindingName] = (...args) => {
const me = window[bindingName];
let callbacks = me['callbacks'];
if (!callbacks) {
Expand Down Expand Up @@ -677,10 +679,12 @@ class Page extends EventEmitter {
* @return {!Promise<?Puppeteer.Response>}
*/
async reload(options) {
const [response] = await Promise.all([
const result = await Promise.all([
this.waitForNavigation(options),
this._client.send('Page.reload')
]);

const response = /** @type Puppeteer.Response */ (result[0]);
return response;
}

Expand Down Expand Up @@ -759,10 +763,11 @@ class Page extends EventEmitter {
const entry = history.entries[history.currentIndex + delta];
if (!entry)
return null;
const [response] = await Promise.all([
const result = await Promise.all([
this.waitForNavigation(options),
this._client.send('Page.navigateToHistoryEntry', {entryId: entry.id}),
]);
const response = /** @type Puppeteer.Response */ (result[0]);
return response;
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -21,7 +21,7 @@
"lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .) && npm run tsc && npm run doc",
"doc": "node utils/doclint/cli.js",
"coverage": "cross-env COVERAGE=true npm run unit",
"tsc": "tsc -p .",
"tsc": "tsc --version && tsc -p .",
"apply-next-version": "node utils/apply_next_version.js",
"bundle": "npx browserify -r ./index.js:puppeteer -o utils/browser/puppeteer-web.js",
"test-types": "node utils/doclint/generate_types && npx -p typescript@3.2 tsc -p utils/doclint/generate_types/test/",
Expand Down Expand Up @@ -61,7 +61,7 @@
"pixelmatch": "^4.0.2",
"pngjs": "^3.3.3",
"text-diff": "^1.0.1",
"typescript": "3.2.2"
"typescript": "3.5.3"
},
"browser": {
"./lib/BrowserFetcher.js": false,
Expand Down
8 changes: 7 additions & 1 deletion utils/doclint/check_public_api/JSBuilder.js
Expand Up @@ -98,7 +98,7 @@ function checkSources(sources) {
function serializeSymbol(symbol, circular = []) {
const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
const name = symbol.getName();
if (symbol.valueDeclaration.dotDotDotToken) {
if (symbol.valueDeclaration && symbol.valueDeclaration.dotDotDotToken) {
const innerType = serializeType(type.typeArguments[0], circular);
innerType.name = '...' + innerType.name;
return Documentation.Member.createProperty('...' + name, innerType);
Expand All @@ -120,6 +120,12 @@ function checkSources(sources) {
return false;
if (type.getCallSignatures().length)
return false;
if (type.isLiteral())
return false;
if (type.isUnion())
return false;


return true;
}

Expand Down