Skip to content

Commit

Permalink
[TypeScript] Upgrade to 4.5.3 (elastic#120812)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianseeders authored and gbamparop committed Jan 12, 2022
1 parent bbac2f7 commit afdc45c
Show file tree
Hide file tree
Showing 25 changed files with 45 additions and 67 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"**/react-syntax-highlighter": "^15.3.1",
"**/react-syntax-highlighter/**/highlight.js": "^10.4.1",
"**/trim": "1.0.1",
"**/typescript": "4.3.5",
"**/typescript": "4.5.3",
"**/underscore": "^1.13.1",
"globby/fast-glob": "3.2.7"
},
Expand Down Expand Up @@ -555,7 +555,7 @@
"@types/js-levenshtein": "^1.1.0",
"@types/js-search": "^1.4.0",
"@types/js-yaml": "^3.11.1",
"@types/jsdom": "^16.2.3",
"@types/jsdom": "^16.2.13",
"@types/json-stable-stringify": "^1.0.32",
"@types/json5": "^0.0.30",
"@types/kbn__ace": "link:bazel-bin/packages/kbn-ace/npm_module_types",
Expand Down Expand Up @@ -836,7 +836,7 @@
"ts-loader": "^7.0.5",
"ts-morph": "^11.0.0",
"tsd": "^0.13.1",
"typescript": "4.3.5",
"typescript": "4.5.3",
"unlazy-loader": "^0.1.3",
"url-loader": "^2.2.0",
"val-loader": "^1.1.1",
Expand Down
6 changes: 5 additions & 1 deletion packages/kbn-test/src/jest/utils/enzyme_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ function getOptions(context = {}, childContextTypes = {}, props = {}) {
/**
* When using @kbn/i18n `injectI18n` on components, props.intl is required.
*/
function nodeWithIntlProp<T>(node: ReactElement<T>): ReactElement<T & { intl: InjectedIntl }> {
// This function is exported solely to fix the types output in TS 4.5.2, likely a bug
// Otherwise, InjectedIntl is missing from the output
export function nodeWithIntlProp<T>(
node: ReactElement<T>
): ReactElement<T & { intl: InjectedIntl }> {
return React.cloneElement<any>(node, { intl });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ describe('RecentlyAccessed#start()', () => {
let originalLocalStorage: Storage;
beforeAll(() => {
originalLocalStorage = window.localStorage;
// @ts-expect-error
window.localStorage = new LocalStorageMock();
});
beforeEach(() => localStorage.clear());
// @ts-expect-error
afterAll(() => (window.localStorage = originalLocalStorage));

const getStart = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/dev/build/lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ export async function deleteEmptyFolders(

// Delete empty is used to gather all the empty folders and
// then we use del to actually delete them
const emptyFoldersList = await deleteEmpty(rootFolderPath, {
const emptyFoldersList = (await deleteEmpty(rootFolderPath, {
// @ts-expect-error DT package has incorrect types https://github.com/jonschlinkert/delete-empty/blob/6ae34547663e6845c3c98b184c606fa90ef79c0a/index.js#L160
dryRun: true,
});
})) as unknown as string[]; // DT package has incorrect types

const foldersToDelete = emptyFoldersList.filter((folderToDelete) => {
return !foldersToKeep.some((folderToKeep) => folderToDelete.includes(folderToKeep));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const EditorMenu = ({ dashboardContainer, createNewVisType }: Props) => {
const factories = embeddable
? Array.from(embeddable.getEmbeddableFactories()).filter(
({ type, isEditable, canCreateNew, isContainerType }) =>
// @ts-expect-error ts 4.5 upgrade
isEditable() && !isContainerType && canCreateNew() && type !== 'visualization'
)
: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export class AttributeService<
try {
const newAttributes = { ...(input as ValType)[ATTRIBUTE_SERVICE_KEY] };
newAttributes.title = props.newTitle;
const wrappedInput = (await this.wrapAttributes(newAttributes, true)) as RefType;
const wrappedInput = (await this.wrapAttributes(
newAttributes,
true
)) as unknown as RefType;

// Remove unneeded attributes from the original input.
const newInput = omit(input, ATTRIBUTE_SERVICE_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class AddPanelFlyout extends React.Component<Props, State> {
private getCreateMenuItems(): ReactElement[] {
return [...this.props.getAllFactories()]
.filter(
// @ts-expect-error ts 4.5 upgrade
(factory) => factory.isEditable() && !factory.isContainerType && factory.canCreateNew()
)
.map((factory) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export function handleKibanaStats(
const { kibana, kibana_stats: kibanaStats, ...plugins } = response;

const os = {
platform: 'unknown',
platformRelease: 'unknown',
...kibanaStats.os,
};
const formattedOsStats = Object.entries(os).reduce((acc, [key, value]) => {
Expand Down
12 changes: 5 additions & 7 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@
"node_modules/@kbn/*",
"bazel-out/darwin-fastbuild/bin/packages/kbn-*",
"bazel-out/k8-fastbuild/bin/packages/kbn-*",
"bazel-out/x64_windows-fastbuild/bin/packages/kbn-*",
"bazel-out/x64_windows-fastbuild/bin/packages/kbn-*"
],
// Allows for importing from `kibana` package for the exported types.
"kibana": ["./kibana"],
"kibana/public": ["src/core/public"],
"kibana/server": ["src/core/server"],
"@emotion/core": [
"typings/@emotion"
],
"resize-observer-polyfill": [
"typings/resize-observer-polyfill"
]
"@emotion/core": ["typings/@emotion"],
"resize-observer-polyfill": ["typings/resize-observer-polyfill"]
},
// Support .tsx files and transform JSX into calls to React.createElement
"jsx": "react",
// Enables all strict type checking options.
"strict": true,
// for now, don't use unknown in catch
"useUnknownInCatchVariables": false,
// All TS projects should be composite and only include the files they select, and ref the files outside of the project
"composite": true,
// save information about the project graph on disk
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/apm/public/application/uxApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export function UXAppRoot({
services={{ ...core, ...plugins, embeddable, data }}
>
<i18nCore.Context>
{/* @ts-expect-error Type instantiation is excessively deep */}
<RouterProvider history={history} router={uxRouter}>
<InspectorContextProvider>
<UrlParamsProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function getServicesDetailedStatistics({
getServiceTransactionDetailedStatistics(commonProps),
offset
? getServiceTransactionDetailedStatistics({ ...commonProps, offset })
: {},
: Promise.resolve({}),
]);

return { currentPeriod, previousPeriod };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const EditorMenu: FC<Props> = ({ addElement }) => {
if (embeddableInput) {
const config = encode(embeddableInput);
const expression = `embeddable config="${config}"
type="${factory.type}"
type="${factory.type}"
| render`;

addElement({ expression });
Expand Down Expand Up @@ -123,6 +123,7 @@ export const EditorMenu: FC<Props> = ({ addElement }) => {
const factories = embeddablesService
? Array.from(embeddablesService.getEmbeddableFactories()).filter(
({ type, isEditable, canCreateNew, isContainerType }) =>
// @ts-expect-error ts 4.5 upgrade
isEditable() &&
!isContainerType &&
canCreateNew() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon
type: string,
id: string,
attributes: Partial<T>,
options?: SavedObjectsUpdateOptions
options?: SavedObjectsUpdateOptions<T>
) {
if (!this.options.service.isRegistered(type)) {
return await this.options.baseClient.update(type, id, attributes, options);
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
DeleteAgentPolicyRequestSchema,
GetFullAgentPolicyRequestSchema,
} from '../../types';
import type { AgentPolicy, NewPackagePolicy } from '../../types';
import { FLEET_SYSTEM_PACKAGE } from '../../../common';
import type {
GetAgentPoliciesResponse,
Expand Down Expand Up @@ -112,10 +111,7 @@ export const createAgentPolicyHandler: RequestHandler<

try {
// eslint-disable-next-line prefer-const
let [agentPolicy, newSysPackagePolicy] = await Promise.all<
AgentPolicy,
NewPackagePolicy | undefined
>([
let [agentPolicy, newSysPackagePolicy] = await Promise.all([
agentPolicyService.create(soClient, esClient, request.body, {
user,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AttributionControl extends Component<Props, State> {
return;
}

const uniqueAttributions = [];
const uniqueAttributions: Attribution[] = [];
for (let i = 0; i < attributions.length; i++) {
for (let j = 0; j < attributions[i].length; j++) {
const testAttr = attributions[i][j];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export class ReportingCsvPanelAction implements ActionDefinition<ActionContext>
const blob = new Blob([rawResponse as BlobPart], { type: 'text/csv;charset=utf-8;' });

// Hack for IE11 Support
// @ts-expect-error
if (window.navigator.msSaveOrOpenBlob) {
// @ts-expect-error
return window.navigator.msSaveOrOpenBlob(blob, download);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export const AutoDownload: React.FC<AutoDownloadProps> = ({ blob, name, onDownlo

useEffect(() => {
if (blob && anchorRef?.current) {
// @ts-expect-error
if (typeof window.navigator.msSaveOrOpenBlob === 'function') {
// @ts-expect-error
window.navigator.msSaveBlob(blob);
} else {
const objectURL = window.URL.createObjectURL(blob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const AnomaliesHostTableComponent: React.FC<AnomaliesHostTableProps> = ({
<BasicTable
// @ts-expect-error the Columns<T, U> type is not as specific as EUI's...
columns={columns}
// @ts-expect-error ...which leads to `networks` not "matching" the columns
items={hosts}
pagination={pagination}
sorting={sorting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const AnomaliesNetworkTableComponent: React.FC<AnomaliesNetworkTableProps> = ({
<BasicTable
// @ts-expect-error the Columns<T, U> type is not as specific as EUI's...
columns={columns}
// @ts-expect-error ...which leads to `networks` not "matching" the columns
items={networks}
pagination={pagination}
sorting={sorting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,11 @@

import { scaleLog } from 'd3-scale';

// Types are from: https://github.com/Microsoft/TypeScript/issues/21309
// TODO: Once this is no longer an experimental web API, remove these below
// as they should be Typed by TypeScript
type RequestIdleCallbackHandle = number;
interface RequestIdleCallbackOptions {
timeout: number;
}
interface RequestIdleCallbackDeadline {
readonly didTimeout: boolean;
timeRemaining: () => number;
}

declare global {
interface Window {
requestIdleCallback: (
callback: (deadline: RequestIdleCallbackDeadline) => void,
opts?: RequestIdleCallbackOptions
) => RequestIdleCallbackHandle;
cancelIdleCallback: (handle: RequestIdleCallbackHandle) => void;
}
}

/**
* Polyfill is from: https://developers.google.com/web/updates/2015/08/using-requestidlecallback
* This is for Safari 12.1.2 and IE-11
*/
export const polyFillRequestIdleCallback = (
callback: (deadline: RequestIdleCallbackDeadline) => void
) => {
export const polyFillRequestIdleCallback = (callback: IdleRequestCallback) => {
const start = Date.now();
return setTimeout(() => {
callback({
Expand All @@ -59,8 +35,8 @@ export const polyFillRequestIdleCallback = (
* this and all usages. Otherwise, just remove this note
*/
export const requestIdleCallbackViaScheduler = (
callback: (deadline: RequestIdleCallbackDeadline) => void,
opts?: RequestIdleCallbackOptions
callback: IdleRequestCallback,
opts?: IdleRequestOptions
) => {
if ('requestIdleCallback' in window) {
window.requestIdleCallback(callback, opts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ describe('Detections Rules API', () => {
name: 'fileToImport',
size: 89,
type: 'json',
webkitRelativePath: '/webkitRelativePath',
arrayBuffer: jest.fn(),
slice: jest.fn(),
stream: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ const fetchAllPoliciesIfNeeded = async (

dispatch({
type: 'policyDetailsListOfAllPoliciesStateChanged',
// @ts-expect-error ts 4.5 upgrade
payload: createLoadingResourceState(asStaleResourceState(currentPoliciesState)),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export const ExpandedRowMessagesPane: React.FC<Props> = ({ transformId }) => {
page = { index: 0, size: 10 },
}: {
page?: { index: number; size: number };
sort?: { field: string; direction: string };
}) => {
const { index, size } = page;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function getRuleData(
const loadedRule: ResolvedRule = await resolveRule(ruleId);
setAlert(loadedRule);

const [loadedAlertType, loadedActionTypes] = await Promise.all<AlertType, ActionType[]>([
const [loadedAlertType, loadedActionTypes] = await Promise.all([
loadAlertTypes()
.then((types) => types.find((type) => type.id === loadedRule.alertTypeId))
.then(throwIfAbsent(`Invalid Rule Type: ${loadedRule.alertTypeId}`)),
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5765,10 +5765,10 @@
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.1.tgz#5c6f4a1eabca84792fbd916f0cb40847f123c656"
integrity sha512-SGGAhXLHDx+PK4YLNcNGa6goPf9XRWQNAUUbffkwVGGXIxmDKWyGGL4inzq2sPmExu431Ekb9aEMn9BkPqEYFA==

"@types/jsdom@^16.2.3":
version "16.2.3"
resolved "https://registry.yarnpkg.com/@types/jsdom/-/jsdom-16.2.3.tgz#c6feadfe0836389b27f9c911cde82cd32e91c537"
integrity sha512-BREatezSn74rmLIDksuqGNFUTi9HNAWWQXYpFBFLK9U6wlMCO4M0QCa8CMpDsZQuqxSO9XifVLT5Q1P0vgKLqw==
"@types/jsdom@^16.2.13":
version "16.2.13"
resolved "https://registry.yarnpkg.com/@types/jsdom/-/jsdom-16.2.13.tgz#126c8b7441b159d6234610a48de77b6066f1823f"
integrity sha512-8JQCjdeAidptSsOcRWk2iTm9wCcwn9l+kRG6k5bzUacrnm1ezV4forq0kWjUih/tumAeoG+OspOvQEbbRucBTw==
dependencies:
"@types/node" "*"
"@types/parse5" "*"
Expand Down Expand Up @@ -27757,10 +27757,10 @@ typescript-tuple@^2.2.1:
dependencies:
typescript-compare "^0.0.2"

typescript@4.3.5, typescript@^3.3.3333, typescript@^3.5.3, typescript@^4.3.5, typescript@~4.4.2:
version "4.3.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
typescript@4.5.3, typescript@^3.3.3333, typescript@^3.5.3, typescript@^4.3.5, typescript@~4.4.2:
version "4.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c"
integrity sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ==

ua-parser-js@^0.7.18:
version "0.7.24"
Expand Down

0 comments on commit afdc45c

Please sign in to comment.