diff --git a/packages/cli/src/api/__snapshots__/compile.test.ts.snap b/packages/cli/src/api/__snapshots__/compile.test.ts.snap index c252b715b..ef777c553 100644 --- a/packages/cli/src/api/__snapshots__/compile.test.ts.snap +++ b/packages/cli/src/api/__snapshots__/compile.test.ts.snap @@ -10,7 +10,7 @@ exports[`createCompiledCatalog options.namespace should compile with global 1`] exports[`createCompiledCatalog options.namespace should compile with json 1`] = `{"messages":{"key":["Hello ",["name"]]}}`; -exports[`createCompiledCatalog options.namespace should compile with ts 1`] = `/*eslint-disable*/import type{Messages}from"@lingui/core";export const messages:Messages=JSON.parse("{\\"key\\":[\\"Hello \\",[\\"name\\"]]}");`; +exports[`createCompiledCatalog options.namespace should compile with ts 1`] = `/*eslint-disable*/import type{Messages}from"@lingui/core";export const messages=(JSON.parse("{\\"key\\":[\\"Hello \\",[\\"name\\"]]}")as Messages);`; exports[`createCompiledCatalog options.namespace should compile with window 1`] = `/*eslint-disable*/window.test={messages:JSON.parse("{\\"key\\":[\\"Hello \\",[\\"name\\"]]}")};`; diff --git a/packages/cli/src/api/compile.ts b/packages/cli/src/api/compile.ts index c1f398f0b..79f9f5dda 100644 --- a/packages/cli/src/api/compile.ts +++ b/packages/cli/src/api/compile.ts @@ -78,16 +78,16 @@ function buildExportStatement( ) importMessagesTypeDeclaration.importKind = "type" - // Create the exported `messages` identifier with a `Messages` TS type annotation - const messagesIdentifier = t.identifier("messages") - messagesIdentifier.typeAnnotation = t.tsTypeAnnotation( + // Cast the expression to `Messages` + const castExpression = t.tsAsExpression( + expression, t.tsTypeReference(t.identifier("Messages")) ) - // export const messages:Messages = { message: "Translation" } + // export const messages = ({ message: "Translation" } as Messages) const exportDeclaration = t.exportNamedDeclaration( t.variableDeclaration("const", [ - t.variableDeclarator(messagesIdentifier, expression), + t.variableDeclarator(t.identifier("messages"), castExpression), ]) )