Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make helper types more explicit #173

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ember-can/src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class EmberObjectAbility extends EmberObject {
*/
getAbility(
propertyName: string,
model?: Model,
model?: Record<string, unknown>,
properties?: Record<string, unknown>,
): unknown {
const abilityValue = get(this, this.parseProperty(propertyName));
Expand All @@ -37,7 +37,3 @@ export default class EmberObjectAbility extends EmberObject {
return abilityValue;
}
}

export interface Model {
[key: string]: unknown;
}
2 changes: 1 addition & 1 deletion ember-can/src/helpers/can.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type Ability from '../services/abilities.ts';

interface CanSignature {
Args: {
Positional: never[];
Positional: [abilityString: string, model?: Record<string, unknown>];
Named: Record<string, unknown>;
};
Return: boolean;
Expand Down
2 changes: 1 addition & 1 deletion ember-can/src/helpers/cannot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type Ability from '../services/abilities.ts';

interface CannotSignature {
Args: {
Positional: never[];
Positional: [abilityString: string, model?: Record<string, unknown>];
Named: Record<string, unknown>;
};
Return: boolean;
Expand Down
10 changes: 5 additions & 5 deletions ember-can/src/services/abilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Service from '@ember/service';
import Ability, { type Model } from '../ability.ts';
import Ability from '../ability.ts';
import { assert } from '@ember/debug';
import { getOwner } from '@ember/application';
import normalizeAbilityString from '../-private/normalize.ts';
Expand All @@ -26,7 +26,7 @@ export default class AbilitiesService extends Service {
*/
abilityFor(
abilityName: string,
model?: Model,
model?: Record<string, unknown>,
properties: Record<string, unknown> = {},
): Ability {
const AbilityFactory = getOwner(this)?.factoryFor(`ability:${abilityName}`);
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class AbilitiesService extends Service {
valueFor(
propertyName: string,
abilityName: string,
model?: Model,
model?: Record<string, unknown>,
properties?: Record<string, unknown>,
): unknown {
const ability = this.abilityFor(abilityName, model, properties);
Expand All @@ -79,7 +79,7 @@ export default class AbilitiesService extends Service {
*/
can(
abilityString: string,
model?: Model,
model?: Record<string, unknown>,
properties?: Record<string, unknown>,
): boolean {
const { propertyName, abilityName } = this.parse(abilityString);
Expand All @@ -96,7 +96,7 @@ export default class AbilitiesService extends Service {
*/
cannot(
abilityString: string,
model?: Model,
model?: Record<string, unknown>,
properties?: Record<string, unknown>,
): boolean {
return !this.can(abilityString, model, properties);
Expand Down