Reputation: 8770
In TypeScript 1.5, I have the following interface in IFoo.ts
:
// IFoo.ts
interface IFoo<T> {
bar(): T;
}
And an implementation in FooString.ts
:
// FooString.ts
export default {
bar: () => 'Hello world'
}
How can the module FooString.ts
declare the object literal it is exporting as an implementation of IFoo<sring>
? Without a declaration, the implementation of the interface is not checked by the compiler, and losing compile-time checking of the FooString
module would be problematic.
Upvotes: 3
Views: 1516
Reputation: 8770
Casting in 1.5 will preserve the compile-time checking, so this will work:
export default <IFoo<string>> {
bar: () => 'Hello world'
}
Upvotes: 2