Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jridgewell/typescript-import-type-without-execution
Demonstrates that TypeScript supports importing a type from an impure file without executing it
https://github.com/jridgewell/typescript-import-type-without-execution
Last synced: about 2 months ago
JSON representation
Demonstrates that TypeScript supports importing a type from an impure file without executing it
- Host: GitHub
- URL: https://github.com/jridgewell/typescript-import-type-without-execution
- Owner: jridgewell
- Created: 2020-07-31T03:39:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-02T22:17:14.000Z (over 3 years ago)
- Last Synced: 2024-10-19T18:31:18.890Z (2 months ago)
- Language: TypeScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Importing types without executing executing other module
> Demonstrates that TypeScript supports importing a type from an impure file without executing it.
TypeScript actually supports two forms of type-only importing:
1. `import type { Type } from 'path/file'` syntax
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-exports
```ts
// This will not execute any code from 'path/file'
import type { Foo as Local } from 'path/file';
```2. `import('path/file').Type` syntax
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
```ts
// This will not execute any code from 'path/file'
type Local = import('path/file').Foo;
```