OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch] TS7053 error in instanceOf methods for required parameters after 7.5.0 (reproducible in 7.9.x snapshot)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
After version 7.5.0, instanceOf methods cause a TS7053 error for required parameters.
openapi-generator version
7.9.0-20240916.120701-53
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
java -jar openapi-generator-cli-7.9.0-20240916.120701-53.jar generate -g typescript-fetch -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o output >> /dev/null && cat output/models/Pet.ts | grep "in value" -B 5 -A 3
/**
* Check if a given object implements the Pet interface.
*/
export function instanceOfPet(value: object): value is Pet {
if (!('name' in value) || value['name'] === undefined) return false;
if (!('photoUrls' in value) || value['photoUrls'] === undefined) return false;
return true;
}
Which causes the following TS error:
TS7053: Element implicitly has an any type because expression of type 'name' can't be used to index type {}
Related issues/PRs
It is similar to https://github.com/OpenAPITools/openapi-generator/issues/19011 but affects any required parameter.
Suggest a fix
Revert === undefined check as in version 7.5.0.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided openapi-generator-cli command and the Pet Store specification, then inspect output/models/Pet.ts and compare it with output from version 7.5.0. Confirm that the generated TypeScript no longer raises TS7053 for required parameters while retaining the required-parameter checks, and verify the generated client compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100