Property 'render' does not exist on type 'typeof Eta'.
retorquere opened this issue · comments
Describe the bug
Typescript compilation errors out with
Property 'render' does not exist on type 'typeof Eta'.
To Reproduce
run this typescript with ts-node (typescript 5.1.3):
import { Eta } from "eta";
const res = Eta.render('Hi, my name is <%= it.name %>', { name: "Ben" });
console.log(res); // Hi Ben!
Expected behavior
I expect this to run and output text to the console
Screenshots
tt.ts:3:17 - error TS2339: Property 'render' does not exist on type 'typeof Eta'.
3 const res = Eta.render('Hi, my name is <%= it.name %>', { name: "Ben" });
Package & Environment Details
- Environment: Node
- Version: 19.8.1
@retorquere thanks for submitting the issue! You need to initialize an instance of Eta
first, then call renderString
(not render
) on that instance.
import { Eta } from "eta";
const eta = new Eta()
const res = eta.renderString('Hi, my name is <%= it.name %>', { name: "Ben" });
console.log(res); // Hi Ben!
I thought I saw the old syntax in the docs, but I can't find it now.
@retorquere you probably did -- I had some troubles with publishing the new docs, so they weren't up to date when I released the package 😅
This happens to me while using the latest syntax as well
Property 'renderString' does not exist on type 'Eta'.
The following test never succeeds.
import {Eta} from 'eta';
describe('[class] TemplateEngine', () => {
test('sets up as eta', () => {
const eta = new Eta()
const res = eta.renderString('Hi, my name is <%= it.name %>', { name: "Ben" });
expect(res).toStrictEqual("Hi Ben!")
});
})
Node Version: v16.18.1
@daredoes you should probably change the last line's output 😉:
expect(res).toStrictEqual("Hi, my name is Ben")
Where are you getting the error that Property 'renderString' does not exist on type 'Eta'
?
@nebrelbug it has something to do with my project's setup. I've gotten this to work by starting a project from scratch.
The error occurs when running jest against that file
I had the same problem as @daredoes. Setting typescript version to "5.1.3" did the job