0

I'm trying to import a function in a class, and the function is located in an other file. I have types.ts with :

export castToString = () => {//implementation}

And in my file form.tsx, I want to import this function :

import {castToString } from '../types.ts'

To use this function, I call it like this :

castToString ()

But it doesn't work, an idea ? Thank you

4
  • what if you try import without brackets around? I believe that's only applicable if exported in brackets too. Commented Aug 28, 2017 at 10:23
  • 2
    Remove .ts from the import and the declaration should be export const castToString = ... Commented Aug 28, 2017 at 10:25
  • @TitianCernicova-Dragomir you should make an answer out of that comment Commented Aug 28, 2017 at 10:27
  • @toskv you are right, but I just wanted to get a bit of confirmation the poster did not miscopy the code Commented Aug 28, 2017 at 10:35

1 Answer 1

3

Remove .ts from the import statement (you will be importing the resulting JS not the TS and you should not specify the extension in either case). Also the declaration should be export const castToString = ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.