Skip to content

Commit

Permalink
Further improve types per feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenet committed May 24, 2021
1 parent 7985ddb commit f5f8213
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function mergeMixins(
} else {
mergeProps(
meta,
currentMixin as { [key: string]: any },
currentMixin as Record<string, unknown>,
descs,
values,
base,
Expand Down
21 changes: 11 additions & 10 deletions packages/@ember/-internals/routing/lib/location/auto_location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ import {
@protected
*/
export default class AutoLocation extends EmberObject implements EmberLocation {
getURL!: () => string;
setURL!: (url: string) => void;
onUpdateURL!: (callback: UpdateCallback) => void;
formatURL!: (url: string) => string;
declare getURL: () => string;
declare setURL: (url: string) => void;
declare onUpdateURL: (callback: UpdateCallback) => void;
declare formatURL: (url: string) => string;

concreteImplementation?: EmberLocation;

implementation = 'auto';

// FIXME: This is never set
// See https://github.com/emberjs/ember.js/issues/19515
/** @internal */
documentMode: number | undefined;

/**
Expand All @@ -85,7 +86,7 @@ export default class AutoLocation extends EmberObject implements EmberLocation {
@default '/'
*/
// Added in reopen to allow overriding via extend
rootURL!: string;
declare rootURL: string;

/**
@private
Expand All @@ -97,7 +98,7 @@ export default class AutoLocation extends EmberObject implements EmberLocation {
@default environment.location
*/
// Added in reopen to allow overriding via extend
location!: any;
declare location: Location;

/**
@private
Expand All @@ -110,7 +111,7 @@ export default class AutoLocation extends EmberObject implements EmberLocation {
@default environment.history
*/
// Added in reopen to allow overriding via extend
history!: any;
declare history: any;

/**
@private
Expand All @@ -122,7 +123,7 @@ export default class AutoLocation extends EmberObject implements EmberLocation {
@default window
*/
// Added in reopen to allow overriding via extend
global!: any;
declare global: any;

/**
@private
Expand All @@ -135,7 +136,7 @@ export default class AutoLocation extends EmberObject implements EmberLocation {
@default environment.history
*/
// Added in reopen to allow overriding via extend
userAgent!: any;
declare userAgent: string;

/**
@private
Expand All @@ -148,7 +149,7 @@ export default class AutoLocation extends EmberObject implements EmberLocation {
@default false
*/
// Added in reopen to allow overriding via extend
cancelRouterSetup!: boolean | undefined;
declare cancelRouterSetup: boolean;

/**
Called by the router to instruct the location to do any feature detection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default class HashLocation extends EmberObject implements EmberLocation {
implementation = 'hash';
_hashchangeHandler?: EventListener;

private _location?: any;
declare location: any;
private _location?: Location;
declare location: Location;

init(): void {
set(this, 'location', this._location || window.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function _uuid() {
@protected
*/
export default class HistoryLocation extends EmberObject implements EmberLocation {
location!: any;
baseURL!: string;
declare location: Location;
declare baseURL: string;

history?: any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { EmberLocation, UpdateCallback } from './api';
@protected
*/
export default class NoneLocation extends EmberObject implements EmberLocation {
updateCallback!: UpdateCallback;
declare updateCallback: UpdateCallback;
implementation = 'none';

// Set in reopen so it can be overwritten with extend
path!: string;
declare path: string;

/**
Will be pre-pended to path.
Expand All @@ -36,7 +36,7 @@ export default class NoneLocation extends EmberObject implements EmberLocation {
@default '/'
*/
// Set in reopen so it can be overwritten with extend
rootURL!: string;
declare rootURL: string;

detect(): void {
let { rootURL } = this;
Expand Down
43 changes: 20 additions & 23 deletions packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
private _names: unknown;

_router!: EmberRouter;
_topLevelViewTemplate!: any;
_environment!: any;
declare _topLevelViewTemplate: any;
declare _environment: any;

constructor(owner: Owner) {
super(...arguments);
Expand All @@ -131,11 +131,11 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
}

// Implement Evented
on!: (name: string, method: ((...args: any[]) => void) | string) => this;
one!: (name: string, method: string | ((...args: any[]) => void)) => this;
trigger!: (name: string, ...args: any[]) => any;
off!: (name: string, method: string | ((...args: any[]) => void)) => this;
has!: (name: string) => boolean;
declare on: (name: string, method: ((...args: any[]) => void) | string) => this;
declare one: (name: string, method: string | ((...args: any[]) => void)) => this;
declare trigger: (name: string, ...args: any[]) => any;
declare off: (name: string, method: string | ((...args: any[]) => void)) => this;
declare has: (name: string) => boolean;

serialize!: (
model: {},
Expand Down Expand Up @@ -190,7 +190,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@public
*/
// Set in reopen so it can be overriden with extend
queryParams!: any;
declare queryParams: Record<string, unknown>;

/**
The name of the template to use by default when rendering this routes
Expand Down Expand Up @@ -223,7 +223,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@public
*/
// Set in reopen so it can be overriden with extend
templateName!: string | null;
declare templateName: string | null;

/**
The name of the controller to associate with this route.
Expand All @@ -246,7 +246,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@public
*/
// Set in reopen so it can be overriden with extend
controllerName!: string | null;
declare controllerName: string | null;

/**
The controller associated with this route.
Expand Down Expand Up @@ -277,7 +277,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@since 1.6.0
@public
*/
controller!: Controller;
declare controller: Controller;

/**
The name of the route, dot-delimited.
Expand All @@ -291,7 +291,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@since 1.0.0
@public
*/
routeName!: string;
declare routeName: string;

/**
The name of the route, dot-delimited, including the engine prefix
Expand All @@ -306,7 +306,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@since 2.10.0
@public
*/
fullRouteName!: string;
declare fullRouteName: string;

/**
Sets the name for this route, including a fully resolved name for routes
Expand Down Expand Up @@ -2207,7 +2207,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
}

// Set in reopen
actions!: Record<string, Function>;
declare actions: Record<string, (...args: any[]) => any>;

/**
Sends an action to the router, which will delegate it to the currently
Expand Down Expand Up @@ -2258,7 +2258,7 @@ class Route extends EmberObject.extend(ActionHandler, Evented) implements IRoute
@public
*/
// Set with reopen to override parent behavior
send!: (name: string, ...args: any[]) => unknown;
declare send: (name: string, ...args: any[]) => unknown;
}

function parentRoute(route: Route) {
Expand All @@ -2271,7 +2271,7 @@ function routeInfoFor(route: Route, routeInfos: InternalRouteInfo<Route>[], offs
return;
}

let current: any;
let current: Route | undefined;
for (let i = 0; i < routeInfos.length; i++) {
current = routeInfos[i].route;
if (current === route) {
Expand Down Expand Up @@ -2388,17 +2388,14 @@ export interface RenderOptions {
into?: string;
outlet: string;
name: string;
controller: unknown;
controller: Controller | string | undefined;
model: unknown;
template: Template;
}

interface PartialRenderOptions {
into?: string;
outlet?: string;
controller?: string | any;
model?: {};
}
type PartialRenderOptions = Partial<
Pick<RenderOptions, 'into' | 'outlet' | 'controller' | 'model'>
>;

export function getFullQueryParams(router: EmberRouter, state: TransitionState<Route>) {
if (state['fullQueryParams']) {
Expand Down
20 changes: 10 additions & 10 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
@public
*/
// Set with reopen to allow overriding via extend
rootURL!: string;
declare rootURL: string;

/**
The `location` property determines the type of URL's that your
Expand All @@ -173,7 +173,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
@public
*/
// Set with reopen to allow overriding via extend
location!: string | IEmberLocation;
declare location: string | IEmberLocation;

_routerMicrolib!: Router<Route>;
_didSetupRouter = false;
Expand All @@ -200,11 +200,11 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
private namespace: any;

// Begin Evented
on!: (name: string, method: ((...args: any[]) => void) | string) => this;
one!: (name: string, method: string | ((...args: any[]) => void)) => this;
trigger!: (name: string, ...args: any[]) => any;
off!: (name: string, method: string | ((...args: any[]) => void)) => this;
has!: (name: string) => boolean;
declare on: (name: string, method: ((...args: any[]) => void) | string) => this;
declare one: (name: string, method: string | ((...args: any[]) => void)) => this;
declare trigger: (name: string, ...args: any[]) => unknown;
declare off: (name: string, method: string | ((...args: any[]) => void)) => this;
declare has: (name: string) => boolean;
// End Evented

// Set with reopenClass
Expand Down Expand Up @@ -1408,7 +1408,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
@since 1.2.0
*/
// Set with reopen to allow overriding via extend
didTransition!: typeof defaultDidTransition;
declare didTransition: typeof defaultDidTransition;

/**
Handles notifying any listeners of an impending URL
Expand All @@ -1421,7 +1421,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
@since 1.11.0
*/
// Set with reopen to allow overriding via extend
willTransition!: typeof defaultWillTransition;
declare willTransition: typeof defaultWillTransition;

/**
Represents the current URL.
Expand All @@ -1431,7 +1431,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
@private
*/
// Set with reopen to allow overriding via extend
url!: string;
declare url: string;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/object/type-tests/compat.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dependentKeyCompat } from '@ember/object/compat';
import { expectTypeOf } from 'expect-type';

expectTypeOf(dependentKeyCompat).toMatchTypeOf<Function>();
expectTypeOf(dependentKeyCompat).toMatchTypeOf<PropertyDecorator>();

0 comments on commit f5f8213

Please sign in to comment.