Skip to content

Commit

Permalink
{{get}} handles ObjectProxy instances
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman committed Mar 31, 2021
1 parent dc80383 commit c7cc5c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/environment-ember-loose/-private/intrinsics/get.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';
import ObjectProxy from '@ember/object/proxy';

export type GetHelper = DirectInvokable<{
<T, K extends keyof T>(args: EmptyObject, obj: T, key: K): T[K];
<T extends object, K extends keyof T>(args: EmptyObject, obj: ObjectProxy<T>, key: K): T[K];
(args: EmptyObject, obj: unknown, key: string): unknown;
}>;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';
import ObjectProxy from '@ember/object/proxy';

let get = resolve(Globals['get']);

Expand All @@ -17,3 +18,10 @@ get(
{},
'hi'
);

// Getting a value off an ObjectProxy
declare const proxiedObject: ObjectProxy<{ name: string }>;

expectTypeOf(get({}, proxiedObject, 'content')).toEqualTypeOf<{ name: string }>();
expectTypeOf(get({}, proxiedObject, 'name')).toEqualTypeOf<string>();
expectTypeOf(get({}, proxiedObject, 'unknownKey')).toEqualTypeOf<unknown>();

0 comments on commit c7cc5c2

Please sign in to comment.