ref: Convert some files to TS (#11929)

This commit is contained in:
Robert Pintilii 2022-07-29 16:18:14 +03:00 committed by GitHub
parent 5783e8992a
commit 69365d7e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 99 additions and 80 deletions

40
package-lock.json generated
View File

@ -146,9 +146,11 @@
"@types/js-md5": "0.4.3",
"@types/lodash": "4.14.182",
"@types/react": "17.0.14",
"@types/react-native": "0.67.6",
"@types/react-native": "0.68.1",
"@types/react-redux": "7.1.24",
"@types/unorm": "1.3.28",
"@types/uuid": "8.3.4",
"@types/zxcvbn": "4.4.1",
"@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.4",
"babel-loader": "8.2.3",
@ -5653,9 +5655,9 @@
}
},
"node_modules/@types/react-native": {
"version": "0.67.6",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.67.6.tgz",
"integrity": "sha512-NM6atxrefIXMLE/PyQ1bIQjQ/lWLdls3uVxItzKvNUUVZlGqgn/uGN4MarM9quSf90uSqJYPIAeAgTtBTUjhgg==",
"version": "0.68.1",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.68.1.tgz",
"integrity": "sha512-S+r6VamWqVutlQ3q/vhTn4b0F/DdZj8R6AIDdgwV9xN9Ln1kRdQd7o3mo7FnfdddVdzEkWMUVlK2sbkFOJFAiQ==",
"dev": true,
"dependencies": {
"@types/react": "*"
@ -5725,6 +5727,12 @@
"@types/node": "*"
}
},
"node_modules/@types/unorm": {
"version": "1.3.28",
"resolved": "https://registry.npmjs.org/@types/unorm/-/unorm-1.3.28.tgz",
"integrity": "sha512-l3uh18vcvkQ964HSK7Tx0YbhxN/Hj+k1w3nLT08n770lngqVKljmF7Ht4e7elFbx6L2WYse97whtpJOo8MHtxQ==",
"dev": true
},
"node_modules/@types/uuid": {
"version": "8.3.4",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
@ -5758,6 +5766,12 @@
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz",
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw=="
},
"node_modules/@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
"integrity": "sha512-3NoqvZC2W5gAC5DZbTpCeJ251vGQmgcWIHQJGq2J240HY6ErQ9aWKkwfoKJlHLx+A83WPNTZ9+3cd2ILxbvr1w==",
"dev": true
},
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "5.30.5",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz",
@ -24977,9 +24991,9 @@
}
},
"@types/react-native": {
"version": "0.67.6",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.67.6.tgz",
"integrity": "sha512-NM6atxrefIXMLE/PyQ1bIQjQ/lWLdls3uVxItzKvNUUVZlGqgn/uGN4MarM9quSf90uSqJYPIAeAgTtBTUjhgg==",
"version": "0.68.1",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.68.1.tgz",
"integrity": "sha512-S+r6VamWqVutlQ3q/vhTn4b0F/DdZj8R6AIDdgwV9xN9Ln1kRdQd7o3mo7FnfdddVdzEkWMUVlK2sbkFOJFAiQ==",
"dev": true,
"requires": {
"@types/react": "*"
@ -25049,6 +25063,12 @@
"@types/node": "*"
}
},
"@types/unorm": {
"version": "1.3.28",
"resolved": "https://registry.npmjs.org/@types/unorm/-/unorm-1.3.28.tgz",
"integrity": "sha512-l3uh18vcvkQ964HSK7Tx0YbhxN/Hj+k1w3nLT08n770lngqVKljmF7Ht4e7elFbx6L2WYse97whtpJOo8MHtxQ==",
"dev": true
},
"@types/uuid": {
"version": "8.3.4",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
@ -25082,6 +25102,12 @@
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz",
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw=="
},
"@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
"integrity": "sha512-3NoqvZC2W5gAC5DZbTpCeJ251vGQmgcWIHQJGq2J240HY6ErQ9aWKkwfoKJlHLx+A83WPNTZ9+3cd2ILxbvr1w==",
"dev": true
},
"@typescript-eslint/eslint-plugin": {
"version": "5.30.5",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz",

View File

@ -151,9 +151,11 @@
"@types/js-md5": "0.4.3",
"@types/lodash": "4.14.182",
"@types/react": "17.0.14",
"@types/react-native": "0.67.6",
"@types/react-native": "0.68.1",
"@types/react-redux": "7.1.24",
"@types/unorm": "1.3.28",
"@types/uuid": "8.3.4",
"@types/zxcvbn": "4.4.1",
"@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.4",
"babel-loader": "8.2.3",

View File

@ -1,7 +1,6 @@
// @flow
// @ts-ignore
import JitsiMeetJS from '../lib-jitsi-meet';
import Platform from '../react/Platform';
import Platform from '../react/Platform.web';
import { isMobileBrowser } from './utils';
@ -15,7 +14,7 @@ const DEFAULT_OPTIMAL_BROWSERS = [
'safari'
];
const DEFAULT_UNSUPPORTED_BROWSERS = [];
const DEFAULT_UNSUPPORTED_BROWSERS: string[] = [];
const browserNameToCheck = {
chrome: browser.isChrome.bind(browser),
@ -27,7 +26,8 @@ const browserNameToCheck = {
safari: browser.isSafari.bind(browser)
};
declare var interfaceConfig: Object;
// eslint-disable-next-line no-var
declare var interfaceConfig: any;
/**
* Returns whether or not jitsi is optimized and targeted for the provided
@ -117,9 +117,9 @@ export function isSupportedMobileBrowser() {
* @private
* @returns {boolean}
*/
function _isCurrentBrowserInList(list) {
function _isCurrentBrowserInList(list: string[]) {
return Boolean(list.find(browserName => {
const checkFunction = browserNameToCheck[browserName];
const checkFunction = browserNameToCheck[browserName as keyof typeof browserNameToCheck];
return checkFunction ? checkFunction.call(browser) : false;
}));

View File

@ -1,5 +1,4 @@
/* @flow */
// @ts-ignore
const { userAgent, maxTouchPoints, platform } = navigator;
let OS;

View File

@ -1,7 +1,5 @@
// @flow
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
import { MiddlewareRegistry } from '../redux';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app/actionTypes';
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
import { USER_INTERACTION_RECEIVED } from './actionTypes';
@ -11,7 +9,7 @@ import { USER_INTERACTION_RECEIVED } from './actionTypes';
*
* @type {Function|null}
*/
let userInteractionListener = null;
let userInteractionListener: Function|null = null;
/**
* Implements the entry point of the middleware of the feature base/user-interaction.
@ -41,7 +39,7 @@ MiddlewareRegistry.register(store => next => action => {
* @private
* @returns {void}
*/
function _onUserInteractionReceived(dispatch, event) {
function _onUserInteractionReceived(dispatch: Function, event: any) {
if (event.isTrusted) {
dispatch({
type: USER_INTERACTION_RECEIVED
@ -58,12 +56,15 @@ function _onUserInteractionReceived(dispatch, event) {
* @private
* @returns {void}
*/
function _startListeningForUserInteraction({ dispatch }) {
function _startListeningForUserInteraction({ dispatch }: {dispatch: Function}) {
_stopListeningForUserInteraction();
userInteractionListener = _onUserInteractionReceived.bind(null, dispatch);
// @ts-ignore
window.addEventListener('mousedown', userInteractionListener);
// @ts-ignore
window.addEventListener('keydown', userInteractionListener);
}
@ -74,7 +75,10 @@ function _startListeningForUserInteraction({ dispatch }) {
* @returns {void}
*/
function _stopListeningForUserInteraction() {
// @ts-ignore
window.removeEventListener('mousedown', userInteractionListener);
// @ts-ignore
window.removeEventListener('keydown', userInteractionListener);
userInteractionListener = null;

View File

@ -1,5 +1,3 @@
// @flow
/**
* Downloads a JSON object.
*

View File

@ -1,5 +1,3 @@
// @flow
import clipboardCopy from 'clipboard-copy';
/**
@ -15,7 +13,7 @@ export function assignIfDefined(target: Object, source: Object) {
for (const nextKey in source) {
if (source.hasOwnProperty(nextKey)) {
const value = source[nextKey];
const value = source[nextKey as keyof typeof source];
if (typeof value !== 'undefined') {
to[nextKey] = value;
@ -49,7 +47,7 @@ export async function copyText(textToCopy: string) {
* @returns {{promise, resolve, reject}}
*/
export function createDeferred(): Object {
const deferred = {};
const deferred: any = {};
deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve;
@ -83,7 +81,7 @@ export function escapeRegexp(s: string) {
* @param {Object} w - Window object to use instead of the built in one.
* @returns {string}
*/
export function getBaseUrl(w: Object = window) {
export function getBaseUrl(w: Window = window) {
const doc = w.document;
const base = doc.querySelector('base');
@ -104,14 +102,19 @@ export function getBaseUrl(w: Object = window) {
* NOTE: After React-ifying everything this should be the only global.
*/
export function getJitsiMeetGlobalNS() {
// @ts-ignore
if (!window.JitsiMeetJS) {
// @ts-ignore
window.JitsiMeetJS = {};
}
// @ts-ignore
if (!window.JitsiMeetJS.app) {
// @ts-ignore
window.JitsiMeetJS.app = {};
}
// @ts-ignore
return window.JitsiMeetJS.app;
}
@ -122,9 +125,9 @@ export function getJitsiMeetGlobalNS() {
* @param {string} msg - A custom message to print in addition to the error.
* @returns {void}
*/
export function reportError(e: Object, msg: string = '') {
export function reportError(e: Error, msg = '') {
console.error(msg, e);
window.onerror && window.onerror(msg, null, null, null, e);
window.onerror && window.onerror(msg, undefined, undefined, undefined, e);
}
/**
@ -168,7 +171,7 @@ export function setColorAlpha(color: string, opacity: number) {
* @param {string} color -
* @returns {Array<number>} - Array containing parsed r, g, b values of the color.
*/
function parseShorthandColor(color) {
function parseShorthandColor(color: string) {
let b, g, r;
r = color.substring(1, 2);

View File

@ -1,4 +1,3 @@
// @flow
import { useSelector } from 'react-redux';
/**

View File

@ -17,7 +17,7 @@ const RETRY_TIMEOUT = 3000;
* @returns {Promise<Object>} The response body, in JSON format, will be
* through the Promise.
*/
export function doGetJSON(url, retry, options) {
export function doGetJSON(url: string, retry?: boolean, options?: Object) {
const fetchPromise = fetch(url, options)
.then(response => {
const jsonify = response.json();

View File

@ -1,5 +1,3 @@
// @flow
import _ from 'lodash';
import { NIL, parse as parseUUID } from 'uuid';
import zxcvbn from 'zxcvbn';
@ -13,7 +11,7 @@ const NIL_UUID = parseUUID(NIL);
* @param {string} str - The string to be checked.
* @returns {boolean} - Whether the string is a valid UUID or not.
*/
function isValidUUID(str) {
function isValidUUID(str: string) {
let uuid;
try {
@ -31,6 +29,6 @@ function isValidUUID(str) {
* @param {string} roomName - The room name.
* @returns {boolean}
*/
export default function isInsecureRoomName(roomName: string = ''): boolean {
export default function isInsecureRoomName(roomName = ''): boolean {
return !isValidUUID(roomName) && zxcvbn(roomName).score < 3;
}

View File

@ -1,5 +1,3 @@
// @flow
/**
* Default timeout for loading scripts.
*/
@ -20,7 +18,7 @@ const DEFAULT_TIMEOUT = 5000;
* @returns {void}
*/
export async function loadScript(
url: string, timeout: number = DEFAULT_TIMEOUT, skipEval: boolean = false): Promise<any> {
url: string, timeout: number = DEFAULT_TIMEOUT, skipEval = false): Promise<any> {
// XXX The implementation of fetch on Android will throw an Exception on
// the Java side which will break the app if the URL is invalid (which
// the implementation of fetch on Android calls 'unexpected url'). In

View File

@ -1,6 +1,5 @@
// @flow
declare var JitsiMeetJS: Object;
// eslint-disable-next-line no-var
declare var JitsiMeetJS: any;
/**
* Loads a script from a specific URL. The script will be interpreted upon load.

View File

@ -1,7 +1,6 @@
// @flow
import { Linking } from 'react-native';
// @ts-ignore
import logger from './logger';
/**

View File

@ -1,5 +1,3 @@
// @flow
/**
* Opens URL in the browser.
*

View File

@ -1,5 +1,4 @@
/* @flow */
// @ts-ignore
import Bourne from '@hapi/bourne';
import { reportError } from './helpers';
@ -24,14 +23,14 @@ const blacklist = [ '__proto__', 'constructor', 'prototype' ];
*/
export function parseURLParams(
url: URL | string,
dontParse: boolean = false,
source: string = 'hash'): Object {
dontParse = false,
source = 'hash'): Object {
if (typeof url === 'string') {
// eslint-disable-next-line no-param-reassign
url = new URL(url);
}
const paramStr = source === 'search' ? url.search : url.hash;
const params = {};
const params: any = {};
const paramParts = (paramStr && paramStr.substr(1).split('&')) || [];
// Detect and ignore hash params for hash routers.
@ -61,7 +60,7 @@ export function parseURLParams(
value = decoded === 'undefined' ? undefined : Bourne.parse(decoded);
}
} catch (e) {
} catch (e: any) {
reportError(
e, `Failed to parse URL parameter value: ${String(value)}`);

View File

@ -10,7 +10,7 @@ import FocusLock, { MoveFocusInside } from 'react-focus-lock';
* @param {Object} props - The props passed to the FocusLock.
* @returns {ReactElement}
*/
export default (props: Object) => {
export default (props: any) => {
const { children, ...otherProps } = props;
const forwardProps = {

View File

@ -1,5 +1,3 @@
// @flow
import * as unorm from 'unorm';
/**

View File

@ -1,5 +1,3 @@
// @flow
/**
* Applies NFKC normalization to the given text.
*

View File

@ -1,5 +1,3 @@
// @flow
/**
* Returns a new {@code Promise} which settles when a specific {@code Promise}
* settles and is automatically rejected if the specified {@code Promise}

View File

@ -1,6 +1,6 @@
// @flow
import { parseURLParams } from './parseURLParams';
// eslint-disable-next-line lines-around-comment
// @ts-ignore
import { normalizeNFKC } from './strings';
/**
@ -53,7 +53,7 @@ export const URI_PROTOCOL_PATTERN = '^([a-z][a-z0-9\\.\\+-]*:)';
* @private
* @returns {?string}
*/
function _fixPathPart(pathPart: ?string) {
function _fixPathPart(pathPart?: string) {
return pathPart
? pathPart.replace(new RegExp(_ROOM_EXCLUDE_PATTERN, 'g'), '')
: pathPart;
@ -107,7 +107,7 @@ function _fixURIStringScheme(uri: string) {
* @param {string?} path - The path to convert.
* @returns {string?}
*/
export function getBackendSafePath(path: ?string): ?string {
export function getBackendSafePath(path?: string): string|undefined {
if (!path) {
return path;
}
@ -124,7 +124,7 @@ export function getBackendSafePath(path: ?string): ?string {
* @param {string?} room - The room name to convert.
* @returns {string?}
*/
export function getBackendSafeRoomName(room: ?string): ?string {
export function getBackendSafeRoomName(room?: string): string|undefined {
if (!room) {
return room;
}
@ -146,10 +146,10 @@ export function getBackendSafeRoomName(room: ?string): ?string {
room = normalizeNFKC(room);
// Only decoded and normalized strings can be lowercased properly.
room = room.toLowerCase();
room = room?.toLowerCase();
// But we still need to (re)encode it.
room = encodeURIComponent(room);
room = encodeURIComponent(room ?? '');
/* eslint-enable no-param-reassign */
// Unfortunately we still need to lowercase it, because encoding a string will
@ -192,7 +192,7 @@ function _objectToURLParamsArray(obj = {}) {
for (const key in obj) { // eslint-disable-line guard-for-in
try {
params.push(
`${key}=${encodeURIComponent(JSON.stringify(obj[key]))}`);
`${key}=${encodeURIComponent(JSON.stringify(obj[key as keyof typeof obj]))}`);
} catch (e) {
console.warn(`Error encoding ${key}: ${e}`);
}
@ -221,7 +221,7 @@ function _objectToURLParamsArray(obj = {}) {
export function parseStandardURIString(str: string) {
/* eslint-disable no-param-reassign */
const obj: Object = {
const obj: {[key: string]: any} = {
toString: _standardURIToString
};
@ -258,6 +258,7 @@ export function parseStandardURIString(str: string) {
authority = authority.substring(userinfoEndIndex + 1);
}
// @ts-ignore
obj.host = authority;
// port
@ -276,7 +277,7 @@ export function parseStandardURIString(str: string) {
regex = new RegExp(`^${_URI_PATH_PATTERN}`, 'gi');
match = regex.exec(str);
let pathname: ?string;
let pathname: string|undefined;
if (match) {
pathname = match[1];
@ -329,7 +330,7 @@ export function parseStandardURIString(str: string) {
* search: string
* }}
*/
export function parseURIString(uri: ?string) {
export function parseURIString(uri?: string) {
if (typeof uri !== 'string') {
return undefined;
}
@ -338,13 +339,14 @@ export function parseURIString(uri: ?string) {
// XXX While the components/segments of pathname are URI encoded, Jitsi Meet
// on the client and/or server sides still don't support certain characters.
obj.pathname = obj.pathname.split('/').map(pathPart => _fixPathPart(pathPart))
obj.pathname = obj.pathname.split('/').map((pathPart: any) => _fixPathPart(pathPart))
.join('/');
// Add the properties that are specific to a Jitsi Meet resource (location)
// such as contextRoot, room:
// contextRoot
// @ts-ignore
obj.contextRoot = getLocationContextRoot(obj);
// The room (name) is the last component/segment of pathname.
@ -371,7 +373,8 @@ export function parseURIString(uri: ?string) {
* function is invoked on such an instance.
* @returns {string}
*/
function _standardURIToString(thiz: ?Object) {
function _standardURIToString(thiz?: Object) {
// @ts-ignore
// eslint-disable-next-line no-invalid-this
const { hash, host, pathname, protocol, search } = thiz || this;
let str = '';
@ -418,7 +421,7 @@ export function safeDecodeURIComponent(text: string) {
* @returns {string} - A {@code String} representation of the specified
* {@code obj} which is supposed to represent a URL.
*/
export function toURLString(obj: ?(Object | string)): ?string {
export function toURLString(obj?: (Object | string)): string|undefined|null {
let str;
switch (typeof obj) {
@ -449,7 +452,7 @@ export function toURLString(obj: ?(Object | string)): ?string {
* @returns {string} - A {@code String} representation of the specified
* {@code Object}.
*/
export function urlObjectToString(o: Object): ?string {
export function urlObjectToString(o: {[key: string]: any}): string|undefined {
// First normalize the given url. It come as o.url or split into o.serverURL
// and o.room.
let tmp;
@ -466,7 +469,7 @@ export function urlObjectToString(o: Object): ?string {
// protocol
if (!url.protocol) {
let protocol: ?string = o.protocol || o.scheme;
let protocol: string|undefined = o.protocol || o.scheme;
if (protocol) {
// Protocol is supposed to be the scheme and the final ':'. Anyway,
@ -484,7 +487,7 @@ export function urlObjectToString(o: Object): ?string {
//
// It may be host/hostname and pathname with the latter denoting the
// tenant.
const domain: ?string = o.domain || o.host || o.hostname;
const domain: string|undefined = o.domain || o.host || o.hostname;
if (domain) {
const { host, hostname, pathname: contextRoot, port }