Flow version: v0.148.0
The following code
const { propName: newPropName }: {| newPropName: string |} = { propName: "..." };
cause the following errors:
propName is missing in object type [1]. [prop-missing]newPropName is missing in object literal [1] but exists in object type [2]. [prop-missing]propName is missing in object type [1] but exists in object literal [2]. [prop-missing]Of course I could do:
const { propName }: {| propName: string |} = { propName: "..." };
const newPropName: string = propName;
which is perfectly fine with Flow but I would love to benefit the very convenient syntaxe above 馃檪
Maybe this is more like a feature request than a bug. I let you choose 馃憤
https://flow.org/try/#0MYewdgzgLgBA3jADgJxIgcgQwLYFMBcMYuA7gAqoY64wC+hcAPkaRWlnodMgJZgDmMRrRgBeeEkocCMAEQA6RbLoBuAFBqA9JpihIsBCnbU6DZkaqcY3PoOFiJF6YQVLVWnXugtyU6lyheAQcnahUgA
I think your syntax is simply wrong. Your object property def should be propName not newPropName as shown below. Because you are not creating a new object with a property of newPropName, you are destructuring the current object, and taking the value propName and then reassigning the variable name after the fact.
If you in fact check the value that flow infers and assigns to newPropName it will be string, as you have typed into propName.
const { propName: newPropName }: {| propName: string |} = { propName: "..." };
https://flow.org/try/#0PTAEGMHsDsGcBdQG9QAcBOlUDkCGBbAUwC5RpCB3ABUxwMNAF9SkAfMymrPI0hdAJbQA5qFaNQAXmRpaPEqABEAOlWKmAbgBQWkBBgIZGbvSYt2xur1D8ho8VKNz6pFWs26wUOInLVn1rYijpby2lrehiihLhz+JkRmyBYBCkH2EtLRqa6qyuqMGkA
Oh, ok I get it, sorry for the confusion. That makes sense.
As the "renamed property" inherit the type it's perfectly fine 馃憤
Most helpful comment
I think your syntax is simply wrong. Your object property def should be
propNamenotnewPropNameas shown below. Because you are not creating a new object with a property ofnewPropName, you are destructuring the current object, and taking the valuepropNameand then reassigning the variable name after the fact.If you in fact check the value that flow infers and assigns to
newPropNameit will bestring, as you have typed intopropName.https://flow.org/try/#0PTAEGMHsDsGcBdQG9QAcBOlUDkCGBbAUwC5RpCB3ABUxwMNAF9SkAfMymrPI0hdAJbQA5qFaNQAXmRpaPEqABEAOlWKmAbgBQWkBBgIZGbvSYt2xur1D8ho8VKNz6pFWs26wUOInLVn1rYijpby2lrehiihLhz+JkRmyBYBCkH2EtLRqa6qyuqMGkA