error TS8016: Type assertion expressions can only be used in TypeScript files. is reported for expr as Type in a .js file, and TS8037 for expr satisfies Type. Both are TypeScript operators; in JavaScript they are syntax errors.
JSDoc has an equivalent for each. A cast is a @type comment directly before a parenthesized expression: /** @type {HTMLInputElement} */ (document.querySelector("#quantity")). @satisfies is a tag on the declaration and checks the value without changing its type.
At a glance
| Code | TS8016 |
|---|---|
| Message | Type assertion expressions can only be used in TypeScript files. |
Also on this page: TS8037 | Type satisfaction expressions can only be used in TypeScript files. |
| TypeScript's category | error |
| Listed under | JavaScript 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 messages are TypeScript's own text from its diagnostic messages file (Apache-2.0).
What it looks like
/** @typedef {{ port: number, host: string }} ServerConfig */
const quantity = document.querySelector("#quantity") as HTMLInputElement;error TS8016: Type assertion expressions can only be used in TypeScript files.
export const config = { port: 3000, host: "localhost" } satisfies ServerConfig;error TS8037: Type satisfaction expressions can only be used in TypeScript files.
export const amount = quantity.valueAsNumber;jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} What causes it
- TypeScript code with
asorsatisfieswas pasted into a.jsfile.
How to fix it
Use a JSDoc cast and @satisfies
The parentheses are required: /** @type {T} */ (value) casts, while a @type comment without them annotates the declaration instead. /** @satisfies {ServerConfig} */ above export const config = { ... } checks the object against the type and keeps its own, narrower type, exactly as satisfies does.
/** @typedef {{ port: number, host: string }} ServerConfig */
const quantity = /** @type {HTMLInputElement} */ (document.querySelector("#quantity"));
/** @satisfies {ServerConfig} */
export const config = { port: 3000, host: "localhost" };
export const amount = quantity.valueAsNumber;type ServerConfig = { port: number; host: string };
const quantity = document.querySelector("#quantity") as HTMLInputElement;
export const config = { port: 3000, host: "localhost" } satisfies ServerConfig;
export const amount = quantity.valueAsNumber;jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} Gotchas
- The older angle-bracket assertion (
<HTMLElement>value) is read as JSX in a.jsfile and produces JSX errors instead of TS8016; it has no JavaScript form either, so use the JSDoc cast. as consthas a JSDoc form too:/** @type {const} */ ([10, 20]).
Sources
- JSDoc Reference: Casts · TypeScript handbook
- JSDoc Reference: @satisfies · TypeScript handbook
- diagnosticMessages.json (TypeScript 5.9.3) · TypeScript on GitHub
Last reviewed 20 October 2026.