Reviewer · Code Style
TypeScript style conventions
Follow consistent TypeScript idioms across the codebase for casting, imports, and function signatures: 1. **Type casting**: Always use the `as` syntax for type assertions instead of angle-bracket casting. Prefer typing the return value of a function correctly over casting its result.
Follow consistent TypeScript idioms across the codebase for casting, imports, and function signatures:
- Type casting: Always use the
assyntax for type assertions instead of angle-bracket casting. Prefer typing the return value of a function correctly over casting its result. ```ts // Avoid const samlWindow =await this.startSAMLAuth(url);
// Prefer const samlWindow = (await this.startSAMLAuth(url)) as Window; // or better, type startSAMLAuth to return Window so no cast is needed
2. **Import organization**: Group type-only imports together and separate them from value imports. Keep imports for a given purpose (e.g. all `import type` statements) contiguous and don't interleave unrelated imports between them.
```ts
// Avoid interleaving
import { filterEnginesByMountType } from 'vault/utils/all-engines-metadata';
import { debug } from '@ember/debug';
import type FlashMessageService from 'vault/services/flash-messages';
// Prefer
import { filterEnginesByMountType } from 'vault/utils/all-engines-metadata';
import { debug } from '@ember/debug';
import type FlashMessageService from 'vault/services/flash-messages';
import type Store from '@ember-data/store';
- Function parameters: When a function takes multiple related parameters, use a destructured object with named parameters instead of a sequence of positional arguments. This improves call-site readability and makes optional/default values explicit. ```ts // Avoid export function filterEnginesByMountType(mountGroup: ‘auth’ | ‘secret’, isEnterprise?: boolean) { … }
// Prefer export function filterEnginesByMountType({ mountGroup, isEnterprise = false, }: { mountGroup: ‘auth’ | ‘secret’; isEnterprise?: boolean; }) { … } ```
Applying these conventions consistently reduces review churn and keeps the codebase predictable for all contributors.