Open in TypeScript playground
interface Item {
name: string
created:Date
}
declare function test(i:Item);
test({name: 'hello', created: new Date})
class MyItem {
constructor(public name:string, public created:Date){}
}
test(new MyItem('hello', new Date))
Open in TypeScript playground
declare function resolve<T>(t:T):PromiseLike<T>
function isPromise<T>(p:any): p is PromiseLike<T> {
return typeof p && p.then === 'function'
}
function add5(p:number|PromiseLike<number>) {
if (isPromise(p)) {
return p.then(v => v + 5)
} else {
return resolve(p + 5)
}
}