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
interfaceInnerObject{foo: number[]bar: string[]}interfaceOuterObject{innerObjects?: InnerObject[]}interfaceSubOuterObject{innerObjects: Array<Pick<InnerObject,'foo'>>}functiontakeSubOuter(_subOuterObject: SubOuterObject): void{}exportfunctionpassDirectly(outerObject: OuterObject): void{if(outerObject.innerObjects){// assert that innerObjects is not undefinedtakeSubOuter(outerObject)// error: Type 'InnerObject[] | undefined' is not assignable to type 'Pick<InnerObject, "foo">[]'}}exportfunctionrecreateThenPass(outerObject: OuterObject): void{if(outerObject.innerObjects){// assert that innerObjects is not undefinedtakeSubOuter({innerObjects: outerObject.innerObjects})// this passes}}
π Actual behavior
In passDirectly, theif type guard fails to make outerObject compatible with SubOuterObject, even though it should have proven that outerObject.innerObjects is not undefined.
π Expected behavior
There should be no compiler errors.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
array of full objects assignable to an array of partial objects.
π Version & Regression Information
(not a regression)
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.2#code/JYOwLgpgTgZghgYwgAgJIhNA8gIwFYQJjIDeAUMpcjAPY0BcyIArgLY7QDaAuhVTnCiMAzmCigA5jzIBfMmVCRYiFFmZLcBIqT6VQmKJsJhhAfkboDRotLkLw0eEmQBlZjjUb8xnVWT7sbyJhRgBBKCg4AE8AHgAFYAQAaxjLQK0wABpkAHJaGhyAPkLZeRhmECJgGhBkMDgkiDcPdWgACgB9YXdPdONGZt7DILAASkYANxpgABNSOwgADwAHGihicsqwatrluGFhABFgKGMAGyi2mlbhjMYh6zHJ6bnyP2AYZCubx4A6ANuxmEo1IyAA9GDkPthNBiGAABZwYgAx7CfxokA0YgVGYQGCgCAzXR+OoNJo9G7fLwZEEQ5DQKBrRgAFSiyxQOTSgJs3GQAB9kDi8QSZjl0UwsVCDsAJCA4DgzigwDQ6myOQlkqkMH0iNkAET5PWFHg5YlyBYrNYbCpVGrIU4IU5IiDM+EQEBxaFUnVge4-EbjZBTWa+KgfL7XanGf7a7kmEEkcGQ6GwuqI5Gx1HizHYkC4-GYIkkqj1RqDSmJlEjELISM+mNWavIGS0yEI4BovYHCDCM2lIA
π» Code
π Actual behavior
In
passDirectly
, theif
type guard fails to makeouterObject
compatible withSubOuterObject
, even though it should have proven thatouterObject.innerObjects
is notundefined
.π Expected behavior
There should be no compiler errors.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: