Closed gooverdian closed 2 years ago
But the types are compatible. Your type ITrl
says all number
properties must be string
, and that's the case (because ISome["translations"]
has no number
properties). Additional properties are allowed in TypeScript.
You probably want #12936.
But the types are compatible. Your type
ITrl
says allnumber
properties must bestring
, and that's the case (becauseISome["translations"]
has nonumber
properties). Additional properties are allowed in TypeScript.You probably want #12936.
But why then direct using of such types causes an error?
Numeric index signatures are a constraint on what types numerically-named keys can have, not a constraint on whether or not non-numeric properties can exist in a type.
Numeric index signatures are a constraint on what types numerically-named keys can have, not a constraint on whether or not non-numeric properties can exist in a type.
@RyanCavanaugh Can you please describe why there is error in my example? It does same thing but interface described directly — nesting is the only difference
For the purposes of assignability, object literal types { ... }
are treated as having an implicit index signature. Types defined using interface
are not. It has nothing directly to do with the nesting; some.translations
has an object literal type while the top-level type ISome
is an interface.
Bug Report
🔎 Search Terms
type compatibility compatibility nested
sry, not many ways I can rephrase that, cos English is not my native language
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
We can pass
some.translations
toChild
despite it having not compatible type.🙂 Expected behavior
Error about types incompatibility