Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Documented how to define custom module formats for the TypeScript compiler so that you can import images and other files #231

Merged
merged 1 commit into from
Jan 20, 2018

Conversation

joshtynjala
Copy link
Contributor

No description provided.

…piler so that you can import images and other files (references #172)
@DorianGrey
Copy link
Collaborator

DorianGrey commented Jan 19, 2018

Are you sure this kind of module definition is sufficient? I've always had to do something like this (example for SVG)

declare module "*.svg" {
  let __svg__: string;
  export default __svg__;
}

to be able to use the imported value in my code without complaints from the compiler, e.g.:

import logo from "../../../importedAssets/logo.svg";

export default () => (
  <div>
    <img src={logo} className="App-logo" alt="logo" />
  </div>
);

Though that might depend on the particular compiler option (esp. regarding noImplicitAny) and typescript version in use.

@joshtynjala
Copy link
Contributor Author

@DorianGrey My tsconfig.json has noImplicitAny set to true, and this was indeed enough for me to import a PNG file without errors.

@DorianGrey
Copy link
Collaborator

Ok, I've cross-checked this - works fine. I'll see if I can figure out why the more complicated version was required some time ago, but the simplified declaration as provided here works fine in recent scenarios.

@DorianGrey DorianGrey merged commit d5e5bb5 into wmonk:master Jan 20, 2018
@wmonk
Copy link
Owner

wmonk commented Jan 22, 2018

Released in 2.13.0

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

Successfully merging this pull request may close these issues.

3 participants