Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module import of non-JSX Javscript from .ts files fails #10

Open
adamcee opened this issue Mar 27, 2018 · 0 comments
Open

Module import of non-JSX Javscript from .ts files fails #10

adamcee opened this issue Mar 27, 2018 · 0 comments

Comments

@adamcee
Copy link

adamcee commented Mar 27, 2018

Description

NOTE After completely rebuilding the project because of facebook/react-native#4968 I am now unable to reproduce this error.

Working on a simple test app, I found that I was getting errors and was unable to import anything from the following file/module when it was named async.ts, but that everything worked fine when it was named async.tsx.

I prefer to distinguish between files with or without JSX by using the appropriate file extension. It's not a big deal to have all files be .tsx, but if that is required it should be noted in the README. Otherwise this project has worked great so far - thank you for putting it together.

// async.tsx
// if something imported, fails if file is named async.ts

// simple async functions
export function getJSONResource(host: string, resourceName: string) {
    return getResource(host, resourceName)
        .then(response => response.json());
}

export function getResource(host: string, resourceName: string) {
    return fetch(`${host}/${resourceName}`)
        .then(handleErrors);
}

export function handleErrors(response: Response) {
    if(!response.ok) {
        throw Error(response.statusText);
    }
    return response;
}

1-2 sentences describing the problem you're having or the feature you'd like to request

Expected Behavior

I would have expected to be able to successfully import code from a file with a .ts extension, as long as no JSX syntax was used.

Observed Behavior

I was unable to import anything and received an error to that effect.

Environment

  • npm ls react-native-scripts-ts: v1.11.4

  • npm ls react-native: v0.52.0

  • npm ls expo: v25.0.0

  • node -v: 6.9.1

  • npm -v: 5.7.1

  • yarn --version: 0.27.5

  • watchman version: 4.9.0

  • Operating system: OS X Sierra 10.12.6

  • Phone/emulator/simulator & version: Both with Expo and iOS Simulator v10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant