Property 'default' of type 'Response | undefined' is not assignable to string index type 'Response'
See original GitHub issueusing package open-api
in a project with "strict": true
in tsconfig.json
causes the error:
Property 'default' of type 'Response | undefined' is not assignable to string index type 'Response'
It would seem that explicitly accepting undefined
in ResponsesObject
fixes it:
export interface ResponsesObject {
[index: string]: Response | undefined;
default?: Response;
}
This happens since version 9.0.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:7 (2 by maintainers)
Top Results From Across the Web
undefined' is not assignable to type 'string' - Stack Overflow
When I make any property of an interface optional ...
Read more >Type 'undefined' is not assignable to type in TypeScript
The "Type 'undefined' is not assignable to type" error occurs when a possibly undefined value is assigned to something that expects a different...
Read more >type 'undefined' is not assignable to type 'string'.ts(2345)
Solution 1: Remove the explicit type definition. Since getPerson already returns a Person with a name, we can use the inferred type. function...
Read more >Documentation - Narrowing - TypeScript
return " ". repeat ( padding ) + input ;. Argument of type 'string | number' is not assignable to parameter of type...
Read more >Typescript `never` type - Explain Programming
Argument of type 'string[]' is not assignable to parameter of type 'ConcatArray<never>'. Types of property 'slice' are incompatible. Type '(start?: number | ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jsdevel I don’t mean to be pushy, but if there is any chance that you could take a look at the linked PR, it would be really helpful. For the moment, we are blocked to update to 9.0.2 because of this.
Thank you for your hard work!
default
is definitely optional, thereforedefault?: Response
is required.IMHO,
[index: string]: Response | undefined
is reasonably, since you will not get aResponse
object back for a randomstring
, e.g.,resp['bla']
orresp.hello
… therefore, you should be “forced” to check forundefined
…