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

[RFC] TS migration patterns #1379

Closed
wants to merge 22 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0fd4a33
LPS-X Enables TypeScript in frontend-js-web module
jbalsas Aug 18, 2021
c603114
LPS-X Adds an initial global Liferay interface
jbalsas Aug 19, 2021
70b78e0
LPS-X Converts autosize and html_util to TS
jbalsas Aug 19, 2021
7a98e2d
LPS-X Converts some trivial modules to TS
jbalsas Aug 19, 2021
0d69c50
LPS-X Converts utility navigate to TS
jbalsas Aug 19, 2021
2c1f090
LPS-X Converts another batch of semi-trivial conversions to TS
jbalsas Aug 19, 2021
2c3f8f8
LPS-X Converts create_X_url utilities to TS
jbalsas Aug 20, 2021
4b22739
LPS-X Refactors logic to help TS infer the proper type for `portletID`
jbalsas Aug 23, 2021
be8ced0
LPS-X Replaces {[key: string]: string} with Record<string, string>
jbalsas Aug 24, 2021
fb25f07
LPS-X Ports fetch utility to TS
jbalsas Aug 24, 2021
6ea38eb
LPS-X Migrates align utility to TS
jbalsas Aug 24, 2021
eda40b9
LPS-X Removes CompatibilityEventProxy
jbalsas Aug 25, 2021
0a7714e
LPS-X Updates form utilities to TS
jbalsas Aug 25, 2021
5f872ac
LPS-X Converts Address utilities to TS
jbalsas Aug 25, 2021
17e37e7
LPS-X Provides a global env.d.ts file for ambient types
jbalsas Sep 7, 2021
23ce0ab
LPS-X Converts EventEmitter utilities to TS
jbalsas Oct 15, 2021
b4136f9
LPS-X Converts run_scripts_in_element utility to TS
jbalsas Oct 15, 2021
be97819
LPS-X Modularizes Liferay global interface for better readability
jbalsas Oct 15, 2021
29a4640
LPS-X Converts module frontend-js-spa-web to TS
jbalsas Oct 15, 2021
c2201e3
LPS-X Converts toggle_disabled utility to TS
jbalsas Oct 15, 2021
bd30aa4
LPS-X Converts focus_form_field, in_browser_view, get_element and get…
jbalsas Oct 18, 2021
092dd31
LPS-X WIP convert module frontend-js-spa-web to TS
jbalsas Oct 20, 2021
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
Prev Previous commit
Next Next commit
LPS-X Converts Address utilities to TS
jbalsas committed Nov 18, 2021
commit 5f872ac9af17f360ea10dd8be5ca269028afae5e
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@ import {showTooltip} from './portal/tooltip.es';
import portlet, {minimizePortlet} from './portlet/portlet.es';
import SideNavigation from './side_navigation.es';
import addParams from './util/add_params';
import getCountries from './util/address/get_countries.es';
import getRegions from './util/address/get_regions.es';
import getCountries from './util/address/get_countries';
import getRegions from './util/address/get_regions';
import fetch from './util/fetch';
import focusFormField from './util/focus_form_field';
import getFormElement from './util/form/get_form_element';
Original file line number Diff line number Diff line change
@@ -81,6 +81,14 @@ export interface ILiferay {
[key: string]: any;
};

Service: {
(
serviceName: string,
payload: any,
callback: (...args: any[]) => void
): void;
};

ThemeDisplay: {
readonly getBCP47LanguageId: () => string;
readonly getCanonicalURL: () => string;
@@ -132,7 +140,7 @@ export interface ILiferay {
readonly currentURLEncoded: string;
}

// Properties from `frontend-js-web/events`
// Properties from `frontend-js-web/liferay/events`

export type Callback = (...args: any[]) => void;

@@ -161,12 +169,16 @@ export interface ILiferay {

declare global {
var Liferay: ILiferay;

// From frontend-js-web/liferay/events.js

var submitForm: (
form: HTMLFormElement,
action?: string,
singleSubmit?: boolean,
validate?: boolean
) => void;

interface Window {
Liferay: ILiferay;
}
Original file line number Diff line number Diff line change
@@ -12,12 +12,16 @@
* details.
*/

interface Country {
countryId: string;
name: string;
nameCurrentValue: string;
}

/**
* Returns a list of countries
* @callback callback
* @return {array} Array of countries
*/
export default function getCountries(callback) {
export default function getCountries(callback: (countries: Country[]) => void) {
if (typeof callback !== 'function') {
throw new TypeError('Parameter callback must be a function');
}
Original file line number Diff line number Diff line change
@@ -12,13 +12,20 @@
* details.
*/

interface Region {
countryId: string;
name: string;
regionCode: string;
regionId: string;
}

/**
* Returns a list of regions by country
* @callback callback
* @param {!string} selectKey The selected region ID
* @return {array} Array of regions by country
*/
export default function getRegions(callback, selectKey) {
export default function getRegions(
callback: (countries: Region[]) => void,
selectKey?: string
) {
if (typeof callback !== 'function') {
throw new TypeError('Parameter callback must be a function');
}
Original file line number Diff line number Diff line change
@@ -12,12 +12,10 @@
* details.
*/

'use strict';

import getCountries from '../../../../src/main/resources/META-INF/resources/liferay/util/address/get_countries.es';
import getCountries from '../../../../src/main/resources/META-INF/resources/liferay/util/address/get_countries';

describe('Liferay.Address.getCountries', () => {
it('throws an error if the callback parameter is not a function', () => {
expect(() => getCountries('')).toThrow('must be a function');
expect(() => getCountries('' as any)).toThrow('must be a function');
});
});
Original file line number Diff line number Diff line change
@@ -12,16 +12,16 @@
* details.
*/

'use strict';

import getRegions from '../../../../src/main/resources/META-INF/resources/liferay/util/address/get_regions.es';
import getRegions from '../../../../src/main/resources/META-INF/resources/liferay/util/address/get_regions';

describe('Liferay.Address.getRegions', () => {
it('throws an error if the callback parameter is not a function', () => {
expect(() => getRegions('')).toThrow('must be a function');
expect(() => getRegions('' as any)).toThrow('must be a function');
});

it('throws an error if the selectKey parameter is not a string', () => {
expect(() => getRegions(() => {}, {})).toThrow('must be a string');
expect(() => getRegions(() => {}, {} as any)).toThrow(
'must be a string'
);
});
});
Original file line number Diff line number Diff line change
@@ -78,6 +78,9 @@ export interface ILiferay {
readonly UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE: number;
[key: string]: any;
};
Service: {
(serviceName: string, payload: any, callback: (...args: any[]) => void): void;
};
ThemeDisplay: {
readonly getBCP47LanguageId: () => string;
readonly getCanonicalURL: () => string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
interface Country {
countryId: string;
name: string;
nameCurrentValue: string;
}
/**
* Returns a list of countries
*/
export default function getCountries(callback: (countries: Country[]) => void): void;
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
interface Region {
countryId: string;
name: string;
regionCode: string;
regionId: string;
}
/**
* Returns a list of regions by country
*/
export default function getRegions(callback: (countries: Region[]) => void, selectKey?: string): void;
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
export {};