Browse documentation

A nested type-only import or export is a SyntaxError, as in TypeScript

Date: 2026-11-30 Area: parser, types as comments, modules Issue: #2450 Related: #2416, Type annotations

Context

An import or export declaration belongs at the top level of a module (ES2026 §16.2). GocciaScript refuses a nested value one, inside a block, a function body or another statement, with An import declaration may only appear at the top level of a module (or An export declaration ...) at its import or export, in a Module and a Script (#2416). That fix kept the type-only forms, which the parse erases, accepted wherever they stood, and left open whether they should be refused too.

TypeScript refuses every nested type-only form at its import or export. tsc 7.0.2 reports TS1232 for import type, TS1233 for export type { ... }, export type { ... } from and export type * from, and TS1184 ("Modifiers cannot appear here") for export type T = ..., export interface and export declare. It accepts a nested type alias or interface without export.

The maintainer decided on 2026-11-30: "Let's be spec compliant to tsc here."

Decision

A nested type-only import or export is refused the way a nested value one is: the same SyntaxError message at its import or export keyword's line and column, in a Module and in a Script. That covers import type in each form, export type lists, re-exports and star re-exports, and exported type aliases, interfaces and ambient declarations. RefuseNestedModuleDeclaration in Goccia.Parser no longer exempts a declaration the parse erased.

At the top level of a file, type-only declarations stay erased. A nested type alias or interface without export stays erased too, as tsc accepts it. The body of a declare module or declare namespace is skipped as a whole, so a declaration inside it is not a nested statement.

GocciaScript's message is the one it already gives a nested value declaration, not tsc's three codes: tsc gives a nested export const TS1184 too, and the position, not the wording, is what the two share.

Consequences

Source with a type-only import or export inside a block or a function body, which ran before, fails to compile until the declaration moves to the top level of the file. tsc already rejects such source, so code that type-checks is unaffected. --warning-unsupported-features does not change this: a nested export function it would skip is refused as well, as any nested export is.