Tooling, Testing & Linting Flashcards
TypeScript with ESLint & Prettier Unit Testing with Jest and ts-jest Typing Mocks Source Maps and Debugging (41 cards)
What is ESLint?
ESLint is a static code analysis tool for identifying problematic patterns in JavaScript/TypeScript code.
What is Prettier?
Prettier is an opinionated code formatter that enforces consistent style by parsing and re-printing code.
Why use ESLint with TypeScript?
ESLint helps catch bugs and enforce best practices by analyzing TypeScript syntax and types using plugins like @typescript-eslint.
What is ts-jest?
ts-jest is a Jest transformer that allows TypeScript code to be tested directly using Jest without a separate compilation step.
What are typing mocks in Jest?
Typing mocks refers to giving proper TypeScript types to mocked functions or modules, avoiding ‘any’ and ensuring type safety.
What are source maps in TypeScript?
Source maps map compiled JavaScript back to the original TypeScript source for easier debugging.
What is the advantage of using ESLint and Prettier together?
ESLint catches code quality issues, while Prettier ensures consistent formatting—together they improve code readability and maintainability.
What is a disadvantage of integrating ESLint, Prettier, and TypeScript?
It requires additional setup, and configuration conflicts may arise if not carefully managed.
What is a best practice when using ESLint with TypeScript?
Use the @typescript-eslint plugin and extend recommended configs to catch both JS and TS issues.
What is a use case for ts-jest?
Unit testing TypeScript code without compiling manually, enabling fast feedback and tight integration with Jest features.
What is a performance implication of ts-jest?
While ts-jest simplifies testing, it can slow down test execution due to on-the-fly transpilation.
What is the architectural impact of using ESLint and Prettier?
Enforces consistent coding standards and prevents code smell across large codebases or teams.
What is a real-world tradeoff with strict lint rules?
Overly strict rules may hinder developer productivity or require excessive boilerplate suppression.
What’s a common interview question around ts-jest?
How do you configure Jest to work with TypeScript using ts-jest?
What is a gotcha when mocking TypeScript modules?
Mocked modules may lose type safety unless properly typed with jest.Mocked or manual typings.
How do source maps help debugging?
They allow debuggers to show TypeScript code instead of transpiled JavaScript when setting breakpoints or reading stack traces.
What is a common ESLint rule for TypeScript?
@typescript-eslint/no-explicit-any warns against using the ‘any’ type, encouraging stronger typing.
What is the advantage of using Prettier over manual formatting?
It automates formatting decisions, removing debates and making code reviews more focused on logic.
What is the benefit of typing mocks in tests?
Maintains type safety in unit tests, reducing runtime bugs and improving test readability.
What is a best practice when mocking TypeScript classes?
Use interfaces or utility types like jest.Mocked<T> to retain type integrity.</T>
What’s a potential issue with source maps in production?
They may expose original source code if not excluded from public builds, posing a security risk.
What is a good way to integrate ESLint and Prettier?
Use eslint-config-prettier to turn off ESLint rules that conflict with Prettier, and run both via scripts or pre-commit hooks.
What’s the impact of tooling on team collaboration?
Consistent linting and formatting prevent merge conflicts and ensure uniform code across contributors.
What’s an example of a Jest mock with types?
jest.mock(‘./api’); const mockedApi = jest.mocked(api);