-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
030d494
commit 53a50dd
Showing
7 changed files
with
6,979 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import ServiceProvider from './serviceProvider'; | ||
export type ServiceKey<T> = keyof T; | ||
|
||
export default interface Container | ||
export default interface Container<T> | ||
{ | ||
get(service: string): any; | ||
get<K extends ServiceKey<T>>(key: K): T[K]; | ||
|
||
has(service: string): boolean; | ||
has<K extends ServiceKey<T>>(key: K): boolean; | ||
} |
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,29 @@ | ||
import Pimple from "./pimple.js"; | ||
import ServiceProvider from "./serviceProvider.js"; | ||
|
||
type ServiceMap = { | ||
'foo.factory': string, | ||
'bar': number, | ||
43: number | ||
} | ||
|
||
class TestServiceProvider implements ServiceProvider<ServiceMap> | ||
{ | ||
register(container: Pimple<ServiceMap>): void { | ||
container.get('bar') | ||
} | ||
|
||
} | ||
|
||
const pimple = new Pimple<ServiceMap>(); | ||
|
||
pimple.set('bar', (): number => { | ||
return 42; | ||
}) | ||
|
||
pimple.set('bar', 42); | ||
|
||
pimple.set('foo.factory', () => 'hello world') | ||
|
||
const bar = pimple.get('bar'); | ||
console.log(typeof bar, bar); |
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
Oops, something went wrong.