Description
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
"typeof string is not assignable to"
"promise"
Code
interface ITest {
name: 'test'
}
const createTestAsync = (): Promise<ITest> => Promise.resolve().then(() => ({ name: 'test' }))
// The same works if you write:
// const createTestAsync = (): Promise<ITest> => Promise.resolve({ name: 'test' })
const createTest = (): ITest => {
return { name: 'test' }
}
Expected behavior:
Expect both sync and async functions (createTest
and createTestAsync
) to compile without errors
Actual behavior:
createTestAsync
throws the following compilation error:
Type 'Promise<{ name: string; }>' is not assignable to type 'Promise<ITest>'.
Type '{ name: string; }' is not assignable to type 'ITest'.
Types of property 'name' are incompatible.
Type 'string' is not assignable to type '"test"'.
Related Issues:
#29078
Further notes
Hi there, first time I'm interacting with the Typescript github repo. I wasn't able to find any issues which described the exact same problem but I wasn't sure exactly what search terms to use so apologies if there are duplicates. Furthermore, I am wondering whether there is something inherent in how Promises work which makes this problem occur - if so, I would love to be educated on the matter! :)
If there is any other information I can provide, please let me know.