79100808

Date: 2024-10-18 06:42:55
Score: 2
Natty:
Report link

You are not really comparing the same things. You mixe declaration with assignation

test4 = 'def'; Error because it's not declared as a variable (let, const, var) before and you are trying to assign a value to something that doesn't exist.

testObj : {key1:'value1'}; Typescript doens't recognize it as a variable declaration but as a "type declaration". You defining the shape but without creating a value for it.

If you try to declare the variable like a = { key1: 'value1' }; you will have the same error.

However, this line (testObj : {key1:'value1'};) is also incomplete because you're not actually declaring the variable, you're just specifying its shape. If you try to use testObj later, TypeScript will throw an error because the variable itself doesn't exist in memory.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): have the same error
  • Low reputation (0.5):
Posted by: MG1616