TypeScript error

TS1247: An initializer in a type literal, often a Closure = in JSDoc

  • Error TS1247
  • Tested with TypeScript 5.9

Closure Compiler marked an optional parameter with a trailing = ({string=}), and older JSDoc carries the habit into object types: {{ street: string, unit: string= }}. TypeScript reads the = as the start of an initializer, which a type cannot have, and reports TS1247, usually together with TS1109 ("Expression expected").

The property stays required, so objects that leave it out then fail too (TS2741 in the example). In a .ts file the same error comes from writing = value inside an interface or type literal.

At a glance

CodeTS1247
MessageA type literal property cannot have an initializer.
TypeScript's categoryerror
Listed underJavaScript files only
Turned on by No option: every checked file reports it
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The message is TypeScript's own text from its diagnostic messages file (Apache-2.0).

What it looks like

address.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: address.js(2,46): error TS1247: A type literal property cannot have an initializer. address.js(2,47): error TS1109: Expression expected. address.js(6,14): error TS2741: Property 'unit' is missing in type '{ street: string; }' but required in type 'Address'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. address.js(2,46): error TS1247: A type literal property cannot have an initializer. address.js(2,47): error TS1109: Expression expected. address.js(6,14): error TS2741: Property 'unit' is missing in type '{ street: string; }' but required in type 'Address'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. address.js(2,46): error TS1247: A type literal property cannot have an initializer. address.js(2,47): error TS1109: Expression expected. address.js(6,14): error TS2741: Property 'unit' is missing in type '{ street: string; }' but required in type 'Address'. checked 21 October 2026
/** @typedef {{ street: string, unit: string= }} Address */error TS1247: A type literal property cannot have an initializer.error TS1109: Expression expected.

/** @type {Address} */
export const address = { street: "12 Market St" };error TS2741: Property 'unit' is missing in type '{ street: string; }' but required in type 'Address'.
A Closure-style optional marker inside a JSDoc object type.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["**/*.js"]
}

What causes it

  • A Closure-style = after a property type inside a JSDoc object type.
  • A default value written into a type instead of into the code.

How to fix it

Mark the property optional with ?

Write unit?: string. Put a default value in the code that reads the property (const { unit = "" } = address), not in the type.

address.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
/** @typedef {{ street: string, unit?: string }} Address */

/** @type {Address} */
export const address = { street: "12 Market St" };
An optional property written with ?.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["**/*.js"]
}

Gotchas

  • The = form is accepted for a whole parameter type, @param {string=} unit, in TypeScript 5.9. TypeScript 7.0 drops much of the Closure syntax, so @param {string} [unit] is the safer spelling (Closure syntax).

Sources

Last reviewed 21 October 2026.