-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from typed-ember/ember-loose-fixes
- Loading branch information
Showing
7 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/environment-ember-loose/-private/intrinsics/each.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { AcceptsBlocks, DirectInvokable } from '@glint/template/-private/integration'; | ||
import EmberArray from '@ember/array'; | ||
|
||
type ArrayLike<T> = ReadonlyArray<T> | Iterable<T> | EmberArray<T>; | ||
|
||
export type EachKeyword = DirectInvokable<{ | ||
<T>(args: { key?: string }, items: ArrayLike<T>): AcceptsBlocks<{ | ||
default: [T, number]; | ||
inverse?: []; | ||
}>; | ||
}>; |
2 changes: 2 additions & 0 deletions
2
packages/environment-ember-loose/-private/intrinsics/get.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/environment-ember-loose/__tests__/intrinsics/each.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { expectTypeOf } from 'expect-type'; | ||
import { Globals, resolve, invokeBlock } from '@glint/environment-ember-loose/-private/dsl'; | ||
import ArrayProxy from '@ember/array/proxy'; | ||
|
||
let each = resolve(Globals['each']); | ||
|
||
// Yield out array values and indices | ||
|
||
invokeBlock(each({}, ['a', 'b', 'c']), { | ||
default(value, index) { | ||
expectTypeOf(value).toEqualTypeOf<string>(); | ||
expectTypeOf(index).toEqualTypeOf<number>(); | ||
}, | ||
inverse(...args) { | ||
expectTypeOf(args).toEqualTypeOf<[]>(); | ||
}, | ||
}); | ||
|
||
// Works for Ember arrays | ||
|
||
declare const proxiedArray: ArrayProxy<string>; | ||
|
||
invokeBlock(each({}, proxiedArray), { | ||
default(value, index) { | ||
expectTypeOf(value).toEqualTypeOf<string>(); | ||
expectTypeOf(index).toEqualTypeOf<number>(); | ||
}, | ||
}); | ||
|
||
// Works for other iterables | ||
|
||
invokeBlock(each({}, new Map<string, symbol>()), { | ||
default([key, value], index) { | ||
expectTypeOf(key).toEqualTypeOf<string>(); | ||
expectTypeOf(value).toEqualTypeOf<symbol>(); | ||
expectTypeOf(index).toEqualTypeOf<number>(); | ||
}, | ||
}); | ||
|
||
// Works for `readonly` arrays | ||
|
||
invokeBlock(each({}, ['a', 'b', 'c'] as readonly string[]), { | ||
default(value, index) { | ||
expectTypeOf(value).toEqualTypeOf<string>(); | ||
expectTypeOf(index).toEqualTypeOf<number>(); | ||
}, | ||
}); | ||
|
||
// Accept a `key` string | ||
invokeBlock(each({ key: 'id' }, [{ id: 1 }]), { | ||
default() { | ||
// Don't yield | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters