You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceMyMap{field: string;}functionsomeGenericFunction<TextendsMyMap>(input: T){lety: Partial<T>;// falsely not allowed: // ts(2322): Type '{ field: ''; }'is not assignable to type 'Partial<T>'. y={field: '',};// similar, but allowedy={};y.field='';// correctly not allowedy.anything='';// anything is not defined in MyMap typey={field: '',anything: 123,// anything is not defined in MyMap type}}
Expected behavior:
Should be able to create the generic in a one-liner .
So you can't safely assign {field: ""} to Partial<T>. For that matter, you can't safely do the assignment y.field = "", but for whatever reason that's allowed by the compiler.
Okay, I see I did not do enough search in the issue history. This issue has a lot of history being closed as duplicate. In fact, item #23015 seems to be exactly the same.
It's still a bug though, as it does not work like expected. Or it should accept both cases, or neither. But I understand that it would be a very breaking change in both cases.
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 3.4.5; 3.7.0-dev.20190829
Search Terms:
Partial, Generic, inconsistent,
Code
Expected behavior:
Should be able to create the generic in a one-liner .
Actual behavior:
Can be done in two lines, not in one line.
Playground Link:
http://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgLIE9VwA7IN4CwAUAJAzAQA2AJgFzIDOYUoA5gNzEC+xxMAriARhgAexCNRAWwgBxCCGjAEAMUHCxIADwAVZBAAekENQZpMOAHwAKUNn5h6OgJT5iJShDDJ09AApwUCJwlLqWnETuAPRRyPCUDFToyCCi3iGUogDuEHTI0bFgDNYATADMJSXOTujYKADkeHEUNPT19ezIXPXAZqnpDAzArCBwAEaeyGCiU7UNAUHAIWH1AHT5pMkAvPjNVHntADRdEQWMwFL8lIHHYw7IGdm57tv4XBEk6Kvk+8g77adIqQYsgEKIoFAIMJKMl+g9KJkctQXqs4CB0GAABZsP7IAHIEE-Gh4tEY7EgVj1ZDUUQQPppfQGXreUCzOrmLDYF64wikMgtA71Q7uEikrFsegARnKx0JApJ6PFFKpNLpKQZhmZyFZYDmHJw7h4RCNQA
Related Issues:
#28470
The text was updated successfully, but these errors were encountered: