Skip to content

Commit

Permalink
Upgrades TypeScript to 4.1, fixes simple errors
Browse files Browse the repository at this point in the history
* Reduces number of errors from 517 across 260 files to 216 across 115
files (~58% reduction).
* The remaining type errors are documented in opensearch-project#1660.

Signed-off-by: Tommy Markley <5437176+tmarkley@users.noreply.github.com>
  • Loading branch information
tmarkley committed Dec 4, 2022
1 parent 808129b commit d902348
Show file tree
Hide file tree
Showing 452 changed files with 733 additions and 736 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### 🛠 Maintenance

- Adding @zhongnansu as maintainer. ([#2590](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2590))
- Upgrades TypeScript to 4.1, fixes simple errors

### 🪛 Refactoring

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const InputEditor = <T,>(props: { input: T; onSubmit: (value: T) => void
try {
JSON.parse(value);
return true;
} catch (e) {
} catch (e: any) {
return false;
}
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function BasicTab() {
setLoading(false);
setResult(String(value));
});
} catch (error) {
} catch (error: any) {
setLoading(false);
setResult(String(error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function PlaygroundSection({
setLoading(false);
setResult(parsedValue);
});
} catch (error) {
} catch (error: any) {
setLoading(false);
setResult(String(error));
}
Expand Down
8 changes: 4 additions & 4 deletions examples/routing_example/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getServices(core: CoreStart): Services {
try {
const response = await core.http.fetch<{ randomNumber: number }>(RANDOM_NUMBER_ROUTE_PATH);
return response.randomNumber;
} catch (e) {
} catch (e: any) {
return e;
}
},
Expand All @@ -62,7 +62,7 @@ export function getServices(core: CoreStart): Services {
{ query: { max } }
);
return response.randomNumber;
} catch (e) {
} catch (e: any) {
return e;
}
},
Expand All @@ -71,7 +71,7 @@ export function getServices(core: CoreStart): Services {
await core.http.post(`${POST_MESSAGE_ROUTE_PATH}/${id}`, {
body: JSON.stringify({ message }),
});
} catch (e) {
} catch (e: any) {
return e;
}
},
Expand All @@ -81,7 +81,7 @@ export function getServices(core: CoreStart): Services {
`${INTERNAL_GET_MESSAGE_BY_ID_ROUTE}/${id}`
);
return response.message;
} catch (e) {
} catch (e: any) {
return e;
}
},
Expand Down
2 changes: 1 addition & 1 deletion examples/search_examples/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const SearchExamplesApp = ({
});

notifications.toasts.addSuccess(`Server returned ${JSON.stringify(response)}`);
} catch (e) {
} catch (e: any) {
notifications.toasts.addDanger('Failed to run search');
}
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"**/nth-check": "^2.0.1",
"**/qs": "^6.10.3",
"**/trim": "^0.0.3",
"**/typescript": "4.0.2",
"**/typescript": "4.1.6",
"**/unset-value": "^2.0.1",
"**/minimatch": "^3.0.5"
},
Expand Down Expand Up @@ -450,7 +450,7 @@
"topojson-client": "3.0.0",
"tough-cookie": "^4.0.0",
"tree-kill": "^1.2.2",
"typescript": "4.0.2",
"typescript": "4.1.6",
"ui-select": "0.19.8",
"vega": "^5.17.3",
"vega-interpreter": "npm:@amoo-miki/vega-forced-csp-compliant-interpreter@1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-ace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@osd/dev-utils": "1.0.0",
"@osd/babel-preset": "1.0.0",
"raw-loader": "^4.0.2",
"typescript": "4.0.2",
"typescript": "4.1.6",
"webpack": "^4.41.5"
}
}
2 changes: 1 addition & 1 deletion packages/osd-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@babel/cli": "^7.16.0",
"@osd/dev-utils": "1.0.0",
"@osd/babel-preset": "1.0.0",
"typescript": "4.0.2"
"typescript": "4.1.6"
}
}
2 changes: 1 addition & 1 deletion packages/osd-analytics/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class Reporter {
try {
// await this.http(this.reportManager.report);
this.flushReport();
} catch (err) {
} catch (err: any) {
this.log(`Error Sending Metrics Report ${err}`);
this.retryCount = this.retryCount + 1;
const versionMismatch =
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-apm-config-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"typescript": "4.0.2",
"typescript": "4.1.6",
"tsd": "^0.21.0"
}
}
6 changes: 3 additions & 3 deletions packages/osd-apm-config-loader/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ export class ApmConfiguration {
try {
const filename = join(dataPath, 'uuid');
return readFileSync(filename, 'utf-8');
} catch (e) {} // eslint-disable-line no-empty
} catch (e: any) {} // eslint-disable-line no-empty
}

private getDevConfig(): ApmAgentConfig {
try {
const apmDevConfigPath = join(this.rootDir, 'config', 'apm.dev.js');
return require(apmDevConfigPath);
} catch (e) {
} catch (e: any) {
return {};
}
}
Expand All @@ -167,7 +167,7 @@ export class ApmConfiguration {
encoding: 'utf-8' as BufferEncoding,
stdio: ['ignore', 'pipe', 'ignore'],
}).trim();
} catch (e) {
} catch (e: any) {
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-config-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@osd/cross-platform": "1.0.0",
"tsd": "^0.21.0",
"typescript": "4.0.2"
"typescript": "4.1.6"
},
"peerDependencies": {
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-config-schema/src/errors/schema_error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const cleanStack = (stack: string) =>
it('includes stack', () => {
try {
throw new SchemaError('test');
} catch (e) {
} catch (e: any) {
expect(cleanStack(e.stack)).toMatchSnapshot();
}
});
14 changes: 7 additions & 7 deletions packages/osd-config-schema/src/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const anyCustomRule: Rules = {
let validationResultMessage;
try {
validationResultMessage = params.validator(value);
} catch (e) {
} catch (e: any) {
validationResultMessage = e.message || e;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ export const internals = Joi.extend([
if (typeof value === 'number') {
return new ByteSizeValue(value);
}
} catch (e) {
} catch (e: any) {
return this.createError('bytes.parse', { value, message: e.message }, state, options);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ export const internals = Joi.extend([
if (typeof value === 'string' || typeof value === 'number') {
return ensureDuration(value);
}
} catch (e) {
} catch (e: any) {
return this.createError('duration.parse', { value, message: e.message }, state, options);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ export const internals = Joi.extend([
return parsed;
}
return this.createError('object.base', { value: parsed }, state, options);
} catch (e) {
} catch (e: any) {
return this.createError('object.parse', { value }, state, options);
}
}
Expand All @@ -297,7 +297,7 @@ export const internals = Joi.extend([
return new Map(Object.entries(parsed));
}
return this.createError('map.base', { value: parsed }, state, options);
} catch (e) {
} catch (e: any) {
return this.createError('map.parse', { value }, state, options);
}
}
Expand Down Expand Up @@ -369,7 +369,7 @@ export const internals = Joi.extend([
return parsed;
}
return this.createError('record.base', { value: parsed }, state, options);
} catch (e) {
} catch (e: any) {
return this.createError('record.parse', { value }, state, options);
}
}
Expand Down Expand Up @@ -433,7 +433,7 @@ export const internals = Joi.extend([
return parsed;
}
return this.createError('array.base', { value: parsed }, state, options);
} catch (e) {
} catch (e: any) {
return this.createError('array.parse', { value }, state, options);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@osd/dev-utils": "1.0.0",
"@osd/utility-types": "1.0.0",
"typescript": "4.0.2",
"typescript": "4.1.6",
"tsd": "^0.21.0"
}
}
2 changes: 1 addition & 1 deletion packages/osd-cross-platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"osd:bootstrap": "yarn build"
},
"devDependencies": {
"typescript": "4.0.2",
"typescript": "4.1.6",
"tsd": "^0.21.0"
}
}
4 changes: 2 additions & 2 deletions packages/osd-cross-platform/src/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Cross Platform', () => {
// If leftover artifacts were found, get rid of them
await access(tmpTestFolder);
await rmdir(tmpTestFolder, { recursive: true });
} catch (ex) {
} catch (ex: any) {
// Do nothing; if `rmdir` failed, let the `mkdir` below throw the error
}

Expand All @@ -61,7 +61,7 @@ describe('Cross Platform', () => {
afterAll(async () => {
try {
await rmdir(tmpTestFolder, { recursive: true });
} catch (ex) {
} catch (ex: any) {
// Do nothing
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-cross-platform/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const getFullPathSync = (path: string) => {

// Make sure we got something back
if (fullName?.length > 2) return fullName;
} catch (ex) {
} catch (ex: any) {
// Do nothing
}

Expand All @@ -80,7 +80,7 @@ const getShortPathSync = (path: string) => {

// Make sure we got something back
if (shortPath?.length > 2) return shortPath;
} catch (ex) {
} catch (ex: any) {
// Do nothing
}

Expand Down
2 changes: 1 addition & 1 deletion packages/osd-cross-platform/src/repo_root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const readOpenSearchDashboardsPkgJson = (dir: string) => {
if (json?.name === 'opensearch-dashboards') {
return json;
}
} catch (error) {
} catch (error: any) {
if (error && error.code === 'ENOENT') {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"@osd/expect": "1.0.0",
"@types/vinyl": "^2.0.4",
"chance": "1.0.18",
"typescript": "4.0.2"
"typescript": "4.1.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class CiStatsReporter {
});

return;
} catch (error) {
} catch (error: any) {
if (!error?.request) {
// not an axios error, must be a usage error that we should notify user about
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class OsdClientRequester {
});

return response;
} catch (error) {
} catch (error: any) {
const conflictOnGet = isConcliftOnGetError(error);
const requestedRetries = options.retries !== undefined;
const failedToGetResponse = isAxiosRequestError(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/precommit_hook/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ run(
await writeFileAsync(installPath, SCRIPT_SOURCE);
await chmodAsync(installPath, 0o755);
log.success(`OpenSearch Dashboards pre-commit git hook was installed successfully.`);
} catch (e) {
} catch (e: any) {
if (isFailError(e)) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-dev-utils/src/proc_runner/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function withTimeout(
attempt(),
new Promise((_, reject) => setTimeout(() => reject(TIMEOUT), ms)),
]);
} catch (error) {
} catch (error: any) {
if (error === TIMEOUT) {
await onTimeout();
} else {
Expand All @@ -88,7 +88,7 @@ export function startProc(name: string, options: ProcOptions, log: ToolingLog) {
if (!statSync(cwd).isDirectory()) {
throw new Error(`cwd "${cwd}" exists but is not a directory`);
}
} catch (err) {
} catch (err: any) {
if (err.code === 'ENOENT') {
throw new Error(`cwd "${cwd}" does not exist`);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ export function startProc(name: string, options: ProcOptions, log: ToolingLog) {
async () => {
try {
await outcomePromise;
} catch (error) {
} catch (error: any) {
// ignore
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/run/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Cleanup {
for (const task of tasks) {
try {
task();
} catch (error) {
} catch (error: any) {
this.onError(error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function run(fn: RunFn, options: RunOptions = {}) {
addCleanupTask: cleanup.add.bind(cleanup),
});
});
} catch (error) {
} catch (error: any) {
cleanup.execute(error);
// process.exitCode is set by `cleanup` when necessary
process.exit();
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/run/run_with_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class RunWithCommands<T> {

await command.run(extendedContext);
});
} catch (error) {
} catch (error: any) {
cleanup.execute(error);
// exitCode is set by `cleanup` when necessary
process.exit();
Expand Down
Loading

0 comments on commit d902348

Please sign in to comment.