Closed
Description
Bug Report
π Search Terms
- Empty object Typescript
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed all of the FAQ's entries.
β― Playground Link
Playground link with relevant code
π» Code
const emptyObject: Record<string, never> = {};
console.log(emptyObject.id); // Should warn, but doesn't
const nonEmptyObject: Record<'a', unknown> = { a: 1 };
console.log(nonEmptyObject.id); // Warning: Property 'id' does not exist on type 'Record<"a", unknown>'
π Actual behavior
I wrapped the Request
type of the Express
library, in order to change the default value of the Request.params
property.
type IEmptyObject = Record<string, never>;
export interface ICustomRequest<P extends IParams = IEmptyObject> extends Request<P> {}
function API(req: ICustomRequest) {
// Expected to get a warning, but didn't
console.log(req.params.anyParam);
}
express.get("/route", API)
If I would give a non-empty type, then it works:
function API(req: ICustomRequest<{definedParam:string}>) {
// Now I get a warning
console.log(req.params.anyParam);
}
π Expected behavior
I should have been warned.