Typescript is a statically typed language, that is a superset of JavaScript. I've had the discussions and debates about that aspect of the language. I am all for static typing. Any way my tools can help me be better is alright by me. So I avoid the 'any' type designation and make sure I have guards on 'unknown' types, as much as I can.
Any does not carry any useful type information, while unknown does, and allows it to enforce type checking. Anything can be assigned to a variable of type unknown, but an unknown value cannot be assigned to variables of other types without explicit type assertion or narrowing. Similarly, no operations are permitted on an unknown value until its type is refined. This behavior ensures type safety and prevents runtime errors. (Refined with help from google). I bring this up because I was arguing with the compiler recently because I'd assumed both made no use on any type information in any circumstance - because I haven't used Typescript in over a year and I am forgetful and make assumptions.
Luckily, my usually bullheaded approach was moderated by a little voice in my head that asked 'why' and I asked google type script unknown and all was revealed. 'Why' is my new question, rather than 'huh?' or 'wtf?'.
Progress.
Secure Your Code with Threat Modeling As a software developer, security should be a top priority. By proactively identifying and addressing potential vulnerabilities, you can significantly reduce the risk of breaches and data loss. What is Threat Modeling? Threat modeling is a systematic approach to identifying, assessing, and mitigating security threats. It involves looking at your system from a hacker's perspective to uncover weaknesses and devise strategies to protect against attacks. See the OWASP Cheat Sheet Why is Threat Modeling Important? Proactive Security: By anticipating potential threats, you can take steps to prevent them. Risk Mitigation: Identify and address vulnerabilities before they can be exploited. Regulatory Compliance: Adhere to industry standards and regulations. Enhanced Security Posture: Strengthen your overall security posture. How to Get Started with Threat Modeling The Threat Modeling Manifesto provides a valuable framewor...
Comments