ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.5k stars 729 forks source link

Property X does not exist on type #405

Closed paul-uz closed 3 years ago

paul-uz commented 3 years ago

I am parsing an object of query params and when accessing the various values, I'm getting the following error

"Property 'size' does not exist on type 'string | ParsedQs | string[] | ParsedQs[]'. Property 'size' does not exist on type 'string'.ts(2339)"

Code

event: {
    queryStringParameters: { 'page[size]': '2' }
}
const queryParams = qs.parse(event.queryStringParameters);
const pageSize = queryParams.page?.size; // error on this line

Oddly, the code works fine, just I get these error messages that are distracting me.

ljharb commented 3 years ago

This package does not contain types, so you'd need to file this on DefinitelyTyped.

paul-uz commented 3 years ago

@ljharb erm OK.

Alternatively, how can I stop those errors appearing at all?

ljharb commented 3 years ago

Stop using typescript?

I’m sure you could cast the return value to a different type and avoid the type error.

paul-uz commented 3 years ago

I'm not using typescript. But I still see the errors in VSCode.

ljharb commented 3 years ago

Ah, I'm not sure how to turn them off entirely, there's probably a vscode setting for it.

Otherwise, the types would have to be fixed in DefinitelyTyped.