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
In auditing some code, I've noticed something that doesn't seem like it should compile. In >=4.95, the following code compiles without an issue, but in <=4.7.4, there is an error. Why is it possible to specify an object for the name of a parameter? This code was likely the result of a bad copy/paste, but TS isn't erroring on it. Am I missing something about the syntax? Also, is the discrepancy between versions intended?
constDEFAULT_NUM_PAGINATED_RESULTS=10;typeIPaginatedParams={first?: number;after?: string;}typeGetPaginatedResults=<Obj,KeyextendskeyofObj>(items: Obj[],{ first =DEFAULT_NUM_PAGINATED_RESULTS, after }: IPaginatedParams,key: Key)=>{items: Obj[];hasMore: boolean};
That looks like… a valid destructuring, I think? The function takes an IPaginatedParams object as its second argument and then destructures it, extracting the first and after properties from it. It is kind of weird to do that in a function type though, since there’s no function body to use the extracted properties—all that matters there is the IPaginatedParams annotation.
Bug Report
In auditing some code, I've noticed something that doesn't seem like it should compile. In >=4.95, the following code compiles without an issue, but in <=4.7.4, there is an error. Why is it possible to specify an object for the name of a parameter? This code was likely the result of a bad copy/paste, but TS isn't erroring on it. Am I missing something about the syntax? Also, is the discrepancy between versions intended?
Playground links for 4.7.4 vs 4.9.5
🔎 Search Terms
function parameter names
The text was updated successfully, but these errors were encountered: