-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function returning Partial<T> allows incorrect objects #49821
Comments
and it looks that doing a direct cast also prevents the error from showing: const person:Partial<Person> = {name: 'Dave', ags: 3} as Partial<Person>; |
This is not a bug, and the objects are not incorrect. Additional properties are allowed. The first error is due to excess property checks, which is more of a linter feature. You get the same behaviour in your second assignment, when you type your fat-arrow function accordingly (add a type annotation that it returns Currently your function
A type assertion (often called a cast) is a way to tell the compiler "please ignore this obvious issue, I know what I'm doing". |
See also #12936 (proposal for Exact Types). |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
Partial
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
There is a single error, when assigning directly to
person
.π Expected behavior
There are two errors, with the same error about
Object literal may only specify known properties, and 'ags' does not exist in type 'Partial<Person>'
for the returned value ofgetPerson
The text was updated successfully, but these errors were encountered: