Hacker News new | ask | show | jobs
by AltruisticGapHN 1670 days ago
Simple object type in TypeScript, the "type checking" abstraction layer on top of JS, which actually doesn't even need to be compiled (eg. esbuild strips all typing from the code before compiling).

https://www.typescriptlang.org/docs/handbook/2/everyday-type...

Your approach is sensible. I remember using json_encode() indeed so I could declare some data in a php file with <<< HEREDOC in the Javascript short syntax (though short array syntax in php nowadays makes it less painful, JSON syntax still a bit less verbose).

1 comments

I checked that example in TS playground and it does nothing when transpiling, so is only a compile type check. From my experience when I have an option object with many properties I would create a class both in PHP and JavaScript, usually functions that need an options object are very complex and many times you need to add even more options and having a class make it simple to do the changes and refactor.