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
I've been away from Typescript for a few months and I'm trying to get back into the swing of things and this one is driving me mad. I have an action function that can return either json({ success: true }) or json({ success: false, errors, formData }). For some reason, TS is inferring the return type of action to be just Promise<TypedResponse<{ success: boolean; }>>. I'm not sure why the rest is getting tossed on the floor.
I have two Playground links, one where I attempt to get TS to infer the correct return type, and another where I have to tell it what the return type is. Am I doing something wrong here? This can't be as difficult as I'm making it out to be, is it?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've been away from Typescript for a few months and I'm trying to get back into the swing of things and this one is driving me mad. I have an action function that can return either
json({ success: true })
orjson({ success: false, errors, formData })
. For some reason, TS is inferring the return type ofaction
to be justPromise<TypedResponse<{ success: boolean; }>>
. I'm not sure why the rest is getting tossed on the floor.I have two Playground links, one where I attempt to get TS to infer the correct return type, and another where I have to tell it what the return type is. Am I doing something wrong here? This can't be as difficult as I'm making it out to be, is it?
Playground for what I'd like to work: https://www.typescriptlang.org/play?target=99#code/JYWwDg9gTgLgBAbzgQQMY2BAdgMQK5bqZbJQDmAzgDRwAqAnmAKYAmASkxZFhUzQFYVscAL5wAZlAgg4AIgACUJiGAAPALRQCAeiwQWTWQG4AUKEixEcAF6iJUmbOv7jJk01UX4qbBXjAKAGFfGCgAQ2AsGABRKCkoOABeOAAKJjjoAC44AgBrPQB3LBofHlCIqOy-KEiyAEokgD5EEzg4JRg8KCxU1ra4dPi4SL8wwiYIcThYoYAyWb622VLqiphZYZ7B6Dh5xbgYRgmp7agAOhXyyPhE27lq2o29-oGM88vw66S7j7W+utMIlM7k80G8ITgYSIwmSYQo9EIqTC5GyaAw2HwhHRJHIFAaiWaCD6lwk0BAABEwjAwkk4AB5ABG-CY6DOkmk0SiNU4KTCBQi8GRZDOSgAjnhODA2WTKdSUnUAW42iSKKgABbKMI4GVUmnJaxnCBMlkwFJEl4QMDZA0AG2AMHSYRtKVkYRYLAA+jAIB7+fa7X5ZHUqPtNcAbdazg8sGR5WdQqA4yosCkAIw0WQccXAJQsINnMPO4N9ESK4kQ8RkgBqTuALCpxFpqo1IC1OupUbC4iYAAVkbwUpWoBTdWW2sApikAIRDkA1u317FRvCoVCcPEtF4dLo9QTYM37NoUFdrigUbLiJ28EMvNqz2VhG+307n0nD+d1hvYAtvNk2qkOimxYvKWphtCI5ZlG+MjJLOH6LsQZyLmEwJtKE9Cbv02jaJCfrwCwDIFqoLJ4A6cYUKKNoAAb7Nh-QjOk-hRBAwxnHhAYwBQaStuGNBUnUtE4W0ABuToSlxAAkCCzgWPE2iINCFPKAkvHRVGof027dHAe4puat7Hqu67ZKEEpPuBirgXAqBUuqqSnA0+njpOATBGUnxRDM0BpG8GZ4KKHoesAgXsQEnGBYWQaOYe7RMJ02m6Qet79IZp6vpeNrXjFd7to+2WvPEr5Ocl0FeVAr4ANqyNEcmQu6ShnsMFCQjaShuhhwgwBqcChX4ZyyAAuuZJXiMATA2iwZVFQp+UzcloH7BB+xdVIBQFdAYGiCYQImEAA
Playground with my explicit return type workaround: https://www.typescriptlang.org/play?target=99#code/JYWwDg9gTgLgBAbzgQQMY2BAdgMQK5bqZbJQDmAzgDRwAqAnmAKYAmASkxZFhUzQFYVscAL5wAZlAgg4AIgACUJiGAAPALRQCAeiwQWTWQG4AUKEixEcAF6iJUmbOv7jJk01UX4qbBXjAKAGFfGCgAQ2AsGABRKCkoOABeOAAKJjjoAC44AgBrPQB3LBofHlCIqOy-KEiyAEokgD5EEzg4JRg8KCxU1ra4dPi4SL8wwiYIcThYoYAyWb622VLqiphZYZ7B6Dh5xbgYRgmp7agAOhXyyPhE27lq2o29-oGM88vw66S7j7W+utMIlMJkOzBQRGwACkhD1En0AD5WCh4VCoTgUbKhPBMUQIlovNrI1Ho7LiMIAG14pgJEmgIAAImEYGFshxOt0GMwADyg45wADyACN+Ex0GdJNJolEapxGtSCacMfiabSoCAZtAlaRwvQuQ8sGQ5fsXuJgExySwNVAlRwfFAWHrQrUaNqwrr9YajTSgfsfR4vHBLnAwhDYcGKPRCL02mFyNk0BhsPhCImSORqCY6tkAAoOAJMLmc1gcLi+AsJ4jQ7CNZqJZoIPpB8R0xnMpIC4WimDihxSp2cFJhAoReCxshnJQAR2xfnFLaZYRSdQBbjaQYoqAAFsowjh523ktYzhBO+gUg2XhAwNkj+TgDB0hSUrIwiwWAB9GAQd-D+93vyyHUVD7DuwDkjeZwekuZxOiA0EqFgKQAIw0LIHDTsASgsIBZygeSS7AW0Igro2ISqiAABqFLACwTLEO2G7biAu77mEkFhOITDZrGvApM2aqtmEJFtMAUwpAAhPxlHUbRqaQSiaIUBQDQXv0HRdD0gjYOexpwESilKmSlJ8LpUmCYRCpvIZdJUXesnELhbziuSTIPohQG+iuRGkWU5HtlJtk0XR2BnLJYTAm0oT0MqbTaNowa-vALCCrhqiingD7QRQk7kgABvscX9CM6T+FEEDDGciX-jAFBpMxYE0EydQFfFbQAG4UjOKQACQIFJuH1eSIg0IUS7NS8hW5RFalMOymkwjpNL6SSBxaCZLzEfKYioEyW6pKcKn7KJqQBMEZSfFEVppG8qF4JO77vsAD1VQENUPXhgGHTS6ndHAWmIapS0KStRm8BZNJmQu4OWfESqAyqUlWkqADasjRINwZvkoSnDBQwbkkor7RcIMDbnAL2zrIAC60MQ2aFpI9kCDDbpRG06IXn9CIq79KTUgFK88RbSYPpAA
Beta Was this translation helpful? Give feedback.
All reactions