Skip to content

Commit 1702cf9

Browse files
author
John Schulz
authored
[Fleet] Use type-only imports where possible (#92979)
## Summary Use [type-only `import`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) to differentiate between runtime values and (erasable) TS types. <img width="1499" alt="Screen Shot 2021-02-27 at 6 34 46 PM" src="https://user-images.githubusercontent.com/57655/109403323-84e32c80-792a-11eb-94b7-854d0e5c3e99.png"> Allows Babel and `tsc` to make some optimizations since it can be sure what can be erased. It can also be helpful in situations like below which highlights that even though `KibanaAssetType` and `KibanaSavedObjectType` are named a certain way and from `common/types`, they are JS values _not_ TS types. They are `enum`s which means they are JS objects at runtime; not eliminated at runtime. https://github.com/elastic/kibana/blob/d92a1a08d89accc2fa303b1355a9e222f9b6d090/x-pack/plugins/fleet/common/types/models/epm.ts#L41-L63
1 parent 92134cb commit 1702cf9

File tree

189 files changed

+483
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+483
-469
lines changed

x-pack/plugins/fleet/common/constants/agent_policy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { defaultPackages } from './epm';
9-
import { AgentPolicy } from '../types';
9+
import type { AgentPolicy } from '../types';
10+
1011
export const AGENT_POLICY_SAVED_OBJECT_TYPE = 'ingest-agent-policies';
1112
export const AGENT_POLICY_INDEX = '.fleet-policies';
1213
export const agentPolicyStatuses = {

x-pack/plugins/fleet/common/constants/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { NewOutput } from '../types';
8+
import type { NewOutput } from '../types';
99

1010
export const OUTPUT_SAVED_OBJECT_TYPE = 'ingest-outputs';
1111

x-pack/plugins/fleet/common/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { NewPackagePolicy, PackagePolicy } from './types';
8+
import type { NewPackagePolicy, PackagePolicy } from './types';
99

1010
export const createNewPackagePolicyMock = (): NewPackagePolicy => {
1111
return {

x-pack/plugins/fleet/common/services/agent_status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { AGENT_POLLING_THRESHOLD_MS, AGENT_SAVED_OBJECT_TYPE } from '../constants';
9-
import { Agent, AgentStatus } from '../types';
9+
import type { Agent, AgentStatus } from '../types';
1010

1111
export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentStatus {
1212
const { last_checkin: lastCheckIn } = agent;

x-pack/plugins/fleet/common/services/full_agent_policy_kibana_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { FullAgentPolicyKibanaConfig } from '../types';
8+
import type { FullAgentPolicyKibanaConfig } from '../types';
99

1010
export function getFullAgentPolicyKibanaConfig(kibanaUrls: string[]): FullAgentPolicyKibanaConfig {
1111
// paths and protocol are validated to be the same for all urls, so use the first to get them

x-pack/plugins/fleet/common/services/full_agent_policy_to_yaml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { safeDump } from 'js-yaml';
9-
import { FullAgentPolicy } from '../types';
9+
import type { FullAgentPolicy } from '../types';
1010

1111
const POLICY_KEYS_ORDER = [
1212
'id',

x-pack/plugins/fleet/common/services/is_agent_upgradeable.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { isAgentUpgradeable } from './is_agent_upgradeable';
9-
import { Agent } from '../types/models/agent';
9+
import type { Agent } from '../types/models/agent';
1010

1111
const getAgent = ({
1212
version,

x-pack/plugins/fleet/common/services/is_agent_upgradeable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import semverCoerce from 'semver/functions/coerce';
99
import semverLt from 'semver/functions/lt';
10-
import { Agent } from '../types';
10+
import type { Agent } from '../types';
1111

1212
export function isAgentUpgradeable(agent: Agent, kibanaVersion: string) {
1313
let agentVersion: string;

x-pack/plugins/fleet/common/services/license.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { Observable, Subscription } from 'rxjs';
9-
import { ILicense } from '../../../licensing/common/types';
9+
import type { ILicense } from '../../../licensing/common/types';
1010

1111
// Generic license service class that works with the license observable
1212
// Both server and client plugins instancates a singleton version of this class

x-pack/plugins/fleet/common/services/limited_package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { PackageInfo, AgentPolicy, PackagePolicy } from '../types';
8+
import type { PackageInfo, AgentPolicy, PackagePolicy } from '../types';
99

1010
// Assume packages only ever include 1 config template for now
1111
export const isPackageLimited = (packageInfo: PackageInfo): boolean => {

0 commit comments

Comments
 (0)