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
{{ message }}
Repository navigation
2.4 errors for missing index signature with object literal spread #16694
error TS2322: Type '{} | { [propertyName: string]: string | number | CSSProperties | undefined; alignContent?: "cente...' is
not assignable to type 'CSSProperties'.
Type '{}' is not assignable to type 'CSSProperties'.
Index signature is missing in type '{}'
The code works fine in 2.3.4 which is what I would expect. I return an object literal, there is nothing that should prevent it to be assigned to a more open type.
Without the tenery at the spread position the code gives no errors.
changed the title [-]2.4 errors for missing index signature with object literal [/-][+]2.4 errors for missing index signature with object literal spread[/+]on Jun 22, 2017
I'm sorry. There were two big issues with the report.
I forgot to mention. The CSSProperties type is from glamorous, not from react. I updated the code in the bug to include the import.
The error message was from my actual code and not the minimal repro. I also updated the bug with the correct error message.
For completeness, here is the actual code where I experienced the bug and its error message:
error TS2322: Type '{ display: string; flexDirection: "column" | "column-reverse"; alignItems: "center" | "flex-start...' is
not assignable to type 'CSSProperties'.
Type '{ display: string; flexDirection: "column" | "column-reverse"; alignItems: "center" | "flex-start...' is not assignable to type 'CSSPropert
ies'.
Index signature is missing in type '{ display: string; flexDirection: "column" | "column-reverse"; alignItems: "center" | "flex-start...'.
The problem is that object types are supposed to have a symbol set, which checkObjectLiteral normally does for spreads. But it forgets to when the result of getSpreadType is a union, as it is for { ...(CSSProperties | undefined) }. The result of the spread, CSSProperties | {}, has two anonymous types that are missing symbols. The former is OK because it has a string indexer that matches the one on CSSProperties (since they are the same type). The latter fails because it doesn't have a string indexer and doesn't have a symbol, which causes it to fail the isObjectLiteralType check.
The predicate in checkObjectLiteralType needs to handle unions when checking TypeFlags.Object and also needs to use mapType to set the symbol. I'll fix this when I have time.
Activity
[-]2.4 errors for missing index signature with object literal [/-][+]2.4 errors for missing index signature with object literal spread[/+]yuit commentedon Jun 22, 2017
Emma (@Pajn) could you share your tsconfig as well just from the code I can't really repro the issue
Pajn commentedon Jun 22, 2017
Here it is:
If it works with a standard config I guess the troublemakers might be
noImplicitAnyorstrictNullChecks. I can't test that right now however.yuit commentedon Jun 22, 2017
Still no luck in repo this .... From the error message, is there more properties in return type of
b.... If so would you be able to share the infoPajn commentedon Jun 22, 2017
I'm sorry. There were two big issues with the report.
I forgot to mention. The CSSProperties type is from glamorous, not from react. I updated the code in the bug to include the import.
The error message was from my actual code and not the minimal repro. I also updated the bug with the correct error message.
For completeness, here is the actual code where I experienced the bug and its error message:
yuit commentedon Jun 22, 2017
We found the reason for this issue that we will fix in the nightly. But in the meantime, the workaround is
to use
{ }sandersn commentedon Jun 22, 2017
The problem is that object types are supposed to have a symbol set, which
checkObjectLiteralnormally does for spreads. But it forgets to when the result ofgetSpreadTypeis a union, as it is for{ ...(CSSProperties | undefined) }. The result of the spread,CSSProperties | {}, has two anonymous types that are missing symbols. The former is OK because it has a string indexer that matches the one on CSSProperties (since they are the same type). The latter fails because it doesn't have a string indexer and doesn't have a symbol, which causes it to fail theisObjectLiteralTypecheck.The predicate in
checkObjectLiteralTypeneeds to handle unions when checking TypeFlags.Object and also needs to usemapTypeto set the symbol. I'll fix this when I have time.Pajn commentedon Jun 23, 2017
Awesome!
sandersn commentedon Oct 5, 2017
Fixed in #18965