Junior — Middle
What versions of TypeScript have you used in your projects?
sobes.tech AI
Answer from AI
Projects with TypeScript often use versions starting from 2.x and above, as they add important improvements and new features.
For example:
- TypeScript 2.0 introduced strict null and undefined checks.
- Versions 3.x added support for optional chaining, improvements in types, and support for new ECMAScript features.
- The latest versions (4.x) introduced template literal types, improved type checking, and other extensions.
The choice of version depends on the project requirements and the tools used. It is important to keep the version up-to-date to utilize modern features and improved typing.
Example of using optional chaining (available from TypeScript 3.7):
interface User {
address?: {
street?: string;
};
}
const user: User = {};
console.log(user.address?.street); // safe access without error