Skip to content

Commit

Permalink
feat(typings): add index.d.ts for custom types
Browse files Browse the repository at this point in the history
we can now add assets like images with typescript import error
  • Loading branch information
nikhilnayyar002 committed Sep 14, 2021
1 parent c154720 commit 45f87a7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** images */

declare module "*.avif"
declare module "*.gif"
declare module "*.apng"
declare module '*.png'
declare module "*.jpg"
declare module "*.jpeg"
declare module "*.jfif"
declare module "*.pjpeg"
declare module "*.pjp"
declare module "*.svg"
declare module "*.webp"
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useState } from 'react';
import { unixEpochInMs } from './common';
import sampleImg from './assets/sample.jpeg';
import sampleJson from './assets/sample.json';

console.log(sampleJson.hello)

export default function App(): JSX.Element {
const [state] = useState(unixEpochInMs)
Expand All @@ -8,6 +12,7 @@ export default function App(): JSX.Element {
<div>
<div>Hello WORLD</div>
<div>{state}</div>
<img src={sampleImg} alt="" width="100" height="100" />
</div>
)
}
Binary file added src/assets/sample.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@styles/*": [
Expand Down Expand Up @@ -29,6 +30,7 @@
"noEmit": false
},
"include": [
"src"
"src/**/*",
"index.d.ts"
]
}

0 comments on commit 45f87a7

Please sign in to comment.