Skip to content
>_ StartupJobList_

Technology decisions

JavaScript vs TypeScript: When to Choose Each

Choose JavaScript for small, low-churn code. Choose TypeScript when shared contracts and frequent refactors justify a type-check step. Both still need runtime validation and tests.

JavaScript runtime behavior compared with TypeScript static analysis, compiler workflow and migration cost.

JavaScript remains the runtime language. TypeScript adds static checking and tooling; it does not validate external values or replace tests.

Compare the practical consequences

Scroll sideways to compare all columns on a smaller screen.

JavaScript and TypeScript by decision criterion
CriterionJavaScriptTypeScriptWhat changes the decision
Run pathRuntime executes JavaScript directly; host/module setup still mattersType annotations need a type-check/erase step or compatible toolchain; output is still JavaScript in ordinary deploymentsTooling adds a check/build contract that CI and developers must run consistently
Contract feedbackTests/runtime checks expose many shape errors laterChecker can reject incompatible calls and incomplete union handling earlierTS pays when contract drift is common; tests remain necessary
External dataRuntime value must be inspectedSame runtime value; annotation/cast does not inspect itBoth need a parser/validator at the boundary
Tiny scriptsFewer files/settings can be a real advantageA type layer can be more ceremony than the script warrantsAvoid converting a stable one-off merely for uniformity
Long-lived shared modulesDynamic contracts can be easy to change and easy to misuseExplicit signatures, narrowing and editor feedback help callers coordinateTypes still need design and can encode the wrong business rule

↑ Back to sections

Are you trying to describe a value or check one?

TypeScript describes what the program expects. It does not transform or inspect an untrusted value. A cast can silence the checker while leaving the bytes unchanged:

The cast's claim is unchecked at runtime. Parse the value from unknown with explicit checks, or use a runtime schema at the boundary, then pass a trusted domain value inward. This remains true even when every internal module is TypeScript.

TS · Worked example
const payload: { id: number } = JSON.parse('{"id":"not-a-number"}') as { id: number };
console.log(payload.id.toFixed(2)); // runtime TypeError: toFixed is not a function

The assertion is erased, so payload.id remains the string "not-a-number"; calling toFixed on that string throws a TypeError. A parser must reject this value or apply an explicitly chosen conversion before treating the ID as numeric.

Illustrative, not executed.

Follow-up: Should every function validate every argument?

No. Validate where data crosses a trust boundary, then keep internal contracts narrow. Rechecking the same invariant in every function adds noise and can create conflicting policies.

Read the source: TypeScript Handbook: Everyday Types · Narrowing

↑ Back to sections

What does a checker catch in a changing contract?

A discriminated union with a never check makes TypeScript report when a newly added variant is unhandled.

If a retrying variant is added, assigning the remaining value to never stops compiling until the switch handles it. JavaScript can express the same switch and tests can cover it, but JavaScript itself has no static exhaustiveness checker. TypeScript still cannot tell whether the policy for denied is correct; it checks handling against the declared shape.

TS · Worked example
type Result =
  | { kind: 'ok'; value: string }
  | { kind: 'missing' }
  | { kind: 'denied'; reason: string };

function message(result: Result): string {
  switch (result.kind) {
    case 'ok': return result.value;
    case 'missing': return 'Not found';
    case 'denied': return result.reason;
    default: {
      const exhaustive: never = result;
      return exhaustive;
    }
  }
}

Adding a retrying variant makes const exhaustive: never = result fail to type-check until the switch handles it. JavaScript can test the new case too, but a test does not make an unhandled union a compiler error.

Illustrative, not executed.

Follow-up: Does this replace tests?

No. It catches incomplete handling against the current declared union. A test checks chosen behavior for real values; the type can itself be wrong or bypassed.

Read the source: TypeScript Narrowing · JavaScript switch statement

↑ Back to sections

Does the project need another build step?

A TypeScript project needs a repeatable type-check command, compatible module and target settings, and a clear owner for emitted JavaScript. Some bundlers erase types while bundling; tsc can type-check without being the production emitter. Do not assume a single pipeline. CI must run the check that developers rely on, or the declared types can drift from runtime behavior.

JavaScript can still use a bundler, tests, lint, and module conversion. Choosing JS does not mean “no tooling”; it means omitting TypeScript's static type layer and its maintenance contract. For a tiny script this can reduce setup. For a service with many callers, omitting a type check may shift cost into review and runtime debugging.

Follow-up: Can I run TypeScript without emitting files?

Yes, a project can use a type-check-only command while another tool handles runtime transformation. Document the actual scripts and versions instead of describing a universal TS pipeline.

Read the source: TSConfig overview · TypeScript Handbook: Modules

↑ Back to sections

What is the safer migration unit?

Migrate a boundary where callers and behavior are understood, not the entire repository in one pass. JavaScript and TypeScript can coexist in a configured project. First make the existing check and test commands reliable. Then type a leaf module or a stable API boundary, enable checking for selected JavaScript where supported, and expand after the first change proves the workflow.

A whole-repo conversion can create a large pile of any and assertions if teams optimize for file extensions instead of contracts. A narrow migration has a measurable result: one contract now fails during checking instead of at runtime, and its callers are covered by tests.

text · Worked example
1. identify one module with stable inputs/outputs
2. add a type check to CI without changing runtime behavior
3. type the boundary and its direct callers
4. replace untrusted `any` with `unknown` plus a parser
5. keep migrating only where checker feedback pays for the added declarations

After converting this boundary, callers must satisfy its declared input and can no longer pass unchecked values without an explicit escape hatch. A repo-wide file rename without typed contracts may compile while leaving the same uncertainty hidden in any and assertions.

Illustrative, not executed.

Follow-up: Should a new project start fully typed?

Often, if the team already knows how it will run checks and maintain compiler settings. A tiny disposable script remains a reasonable exception.

Read the source: TypeScript: Migrating from JavaScript · TSConfig allowJs · checkJs

↑ Back to sections

Which scenario favors which tool?

Use JavaScript for small, low-churn code with few callers when checker upkeep costs more than the failures it prevents. Use TypeScript when shared contracts and refactors make early feedback valuable; reconsider either choice when the code or maintenance burden changes.

Long-lived API client shared by several product modules. TypeScript is a stronger fit when response shapes and error states are modeled as unions and the type check runs in CI. It catches caller drift as the client evolves. It does not establish that the server actually returns that shape; validate or generate from a trusted schema at runtime as needed.

Existing JS application with costly regressions but limited migration time. Start incrementally at the module boundaries with the most callers. Keep JS elsewhere. If the team cannot maintain the checker or CI remains unreliable, the predicted benefit will not arrive; improve that operating path before increasing typed coverage.

Follow-up: What would make you reverse a TypeScript decision?

A small stable module with near-zero contract churn, a type layer that mostly repeats obvious literals, or an unreliable check that nobody runs. Reverse a JavaScript decision when callers repeatedly disagree about shapes or a refactor cannot safely reveal all affected code.

Read the source: TypeScript Handbook · JavaScript Guide

↑ Back to sections

What does the comparison leave to runtime tests?

Both languages need tests for side effects, ordering, race conditions, browser behavior, authorization and persistence. A TypeScript type may prevent calling save() with a string where a record is declared, but cannot ensure a promise resolves before a timeout or that two writes are atomic. Test the behavior at the level users depend on.

Use the static check for relationships it can establish, runtime validation for external input, and tests for observable behavior. Those tools overlap in some places but solve different failures.

Follow-up: What should you check before applying this in a different system?

Confirm the runtime, version and ownership assumptions described here against the real application, then test the externally visible behavior at the boundary that depends on them.

Read the source: TypeScript Handbook: Type compatibility · TypeScript Narrowing

↑ Back to sections

Salary context

Advertised salaries for these skills

These are Hacker News job posts that mention these technologies, not employee earnings or a measure of what a skill adds to pay. The amounts summarize annualized advertised minimums in approximate USD. Groups can overlap and differ in roles, locations and dates.

JavaScript posts

79 posts · 79 usable advertised salary amounts

2024-07-01 to 2026-11-04

$130,000

Median advertised minimum, approximate USD/year

Middle 50%: $100,000–$150,000

Explore JavaScript salaries → Browse matching job posts →
Currency and calculation basis

Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged JavaScript, rather than every job in the broader technology family.

TypeScript posts

464 posts · 464 usable advertised salary amounts

2024-07-01 to 2026-11-09

$148,000

Median advertised minimum, approximate USD/year

Middle 50%: $107,191–$170,000

Explore TypeScript salaries → Browse matching job posts →
Currency and calculation basis

Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged TypeScript, rather than every job in the broader technology family.

Middle-half salary ranges on one shared scale

The band runs from the 25th to 75th percentile; the vertical marker is the median. Both rows use approximate USD per year.

JavaScript $130,000 median
TypeScript $148,000 median
$100,000$170,000

32 posts mention both technologies. That is 40.5% of JavaScript posts and 6.9% of TypeScript posts. A post can belong to both groups. This overlap does not show that employers prefer one technology, and the two salary groups are not independent samples.

↑ Back to sections

Keep exploring