I want to write a class as follows:
class Foo { public someProp = '123'; }
but I made a mistake and wrote this:
class Foo{ public someProp: '123'; // not "=" }
I expect to get a compilation error, but nothing will happen. Why is this so?
Because TypeScript supports the constatnts type as a type, when you need to specify valid values ββin a field. It's not a mistake. This is a feature. :)
var x: '123'; var y: '123' | '456'; x = '123'; x = '456'; // Error x = '789'; // Error y = '123'; y = '456'; y = '789'; // Error
see TypeScript Playground
Source: https://habr.com/ru/post/1269635/More articles:Async Validator Throw Expected Validator for Returning Promises or Observations - angularSave one decimal digit - c ++Create a self-signed certificate for testing the local host and its approval by browsers - windowsUpdate ttl for all entries in aerosics - luaStateT over Cont. Why is my condition not reset? - haskellWhy doesn't an array match Equatable when its elements are Equableable in Swift? - arraysUploading a file in vuetify - javascriptIOS 11 XCODE 9: Archive Errors Undefined Symbols for arm64 Architecture: - ios11How does the `__getattribute__` method participate in search procedures? - pythonPython 3 __getattribute__ vs dot access behavior - pythonAll Articles