You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compilation Error in the function fetchBookWithAuthor2
Type 'Author | BookWithAuthor' is not assignable to type 'Author'.
Property 'name' is missing in type 'BookWithAuthor' but required in type 'Author'.(2322)
input.ts(17, 29): 'name' is declared here.
🙂 Expected behavior
No errors.
compilation result must be the same as for fetchBookWithAuthor1.
The only difference between two versions of the function is a return type specified.
Slightly reduced (could go farther probably) + annotated
interfaceResult<T,E>{[Symbol.iterator](): Generator<E,T>}typeNotResultOf<T>=TextendsResult<any,any> ? never : T;typeErrTypeOf<T>=TextendsResult<unknown, infer E> ? E : never;typeOkTypeOf<T>=TextendsResult<infer R,unknown> ? R : never;typeAsyncJob<T,E>=()=>AsyncGenerator<E,T>;declareconstasyncDo: <T,E>(job: AsyncJob<T,E>)=>Promise<Result<OkTypeOf<T>|NotResultOf<T>,E|ErrTypeOf<T>>>;declareconstmapErr: <E,F>(mapper: (error: E)=>F)=><T>(result: Result<T,E>)=>Result<T,F>;typeBook={id: string;title: string;authorId: string};typeAuthor={id: string;name: string};typeBookWithAuthor=Book&{author: Author};declareconstfetchAuthor: (id: string)=>Promise<Result<Author,"NOT_FOUND">>;letauthorId: string="";constf1=asyncDo(asyncfunction*(){constauthor: Author=yield*awaitfetchAuthor(authorId)returnnull!asBookWithAuthor;});constf2: Promise<Result<BookWithAuthor,"NOT_FOUND_BOOK"|"NOT_FOUND_AUTHOR">>=asyncDo(asyncfunction*(){// Without yield*, the type of test1 is// Result<Author, "NOT_FOUND_AUTHOR>consttest1=awaitfetchAuthor(authorId).then(mapErr(()=>"NOT_FOUND_AUTHOR"asconst))// ^?// With yield*, the type of test2 is// Author | BookWithAuthor// But this codepath has no way to produce BookWithAuthorconsttest2=yield*awaitfetchAuthor(authorId).then(mapErr(()=>"NOT_FOUND_AUTHOR"asconst))// ^?returnnull!asBookWithAuthor;});
Uh oh!
There was an error while loading. Please reload this page.
🔎 Search Terms
async generator inference, async generator
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?target=99&jsx=0&ts=5.4.3#code/JYOwLgpgTgZghgYwgAgEoQM4FcA2YA8AKgDTICiAfMgN4BQyyA2gMoCeAtgEYD2OAdMEhQ4YblAC6ACgCUALmQBxCCGgix+MqUIVaAX1q0wrAA4oActzDpseAPIwiVALzJCyCAA9IIACYY0mLgEcCCspCGsVAD8yCoAbtDI8oQA3IYmKGRQUIQZ9o7ILm6e3n4BNgRYIADWINwA7iCkoDCJlMgxZEmxEAlQaUamyLbVuab52oWu7l7KZdZB+C2JqKRVtQ0g0Wjd8dADGcgAghisIAgAUtycRKTtLjKFVCdnCEoqwqJQGloUabQ+CAIHBwKAoBDcEAYMDIOCnc4AEW48lu5AokgAVtd5C9zlcbiQ0dInsgAApQbjsYAYCD4BZ4fD0YajPIOSYAH2QFisgTsbIoxCZXU5WRyrMctAofwBQJBYOQEKhMPYcGMopRmmQADF0SrjKYoPJJNAKYbyMSnFQtRaqI5JGCKvJ6QRCZQbeVFoSdf9BigAELcbjVKbUZDAHzyaFQUAAcxSyDAghwEEjYGjIDjsKwYAAFmIAJIR5BR2PIXQHIZHbN5qAhsNFksZ+MgODsFPFtOl8vpIYBoMAdUEOarubEUz7wYAZDQs6OzSOa2X-oDgaDwZDochWmAEDmJ0bw6n0zH3eTKdTac78BPSAAiMy2QgAfS1tgAqmYEbepcvZWuFRuMLbruC5iAeDadhmp4UlSNJ0ryBCgVAd4Ps+r4fl+P4GJ4xhiDCiqbsBe6BtUg65khACMhRMpIPBBoWR6xjaTIMHCrxIpIbHnFuVQIImkIAFTII8dAMGJAFKsgdHVPIE5TKwwAQDgPhCXA9RwIIW4QDuxFBrRJGFtILHicgfC5sokh6qKkiPJayD3o+L7vp+T5+rYtgANK3rC-gEWA0hGcZDB+bONY4tWY4uApSkqbC6maURSH6UGfBwBFUCGUFYlmTmFlWdkNnug5aHOQiT5HG+hAABK2Kg3lwhJ0IBQYJnIGCYBYFAIAznwvXSeE6Vlj5yATmRw7pWk4m6NI-w4XhjVAdpu6jUOSEAEzUQwyXVAxHbHnIZIwRe8EVNeJFjUhKGOehLluZ53mcsVTkYeVlU1XVUpPMZXEIBxP08ec-EgEJIlZSF0mySR8mKcpqnxYtOkTttmWtQwOV5aq1m2VQT03WVd1ecNfnNWDgGhWBxyDVFMOxWpGkIyB6Xbal6Uo6j6MgJZmMFdj9moc9LkVdVtX1b5gEk617Wdd1oa9Xw-Xk7WujDSt5ETcZ01pEAA
💻 Code
🙁 Actual behavior
Compilation Error in the function
fetchBookWithAuthor2
🙂 Expected behavior
No errors.
compilation result must be the same as for
fetchBookWithAuthor1
.The only difference between two versions of the function is a return type specified.
The defenition file is emitted correctly:
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: