Dynamic import する Component に 型をつける
repo_url
date
Jul 15, 2021
thumbnail_url
slug
type-dynamic-import
status
Published
tags
tech
summary
Type-Only Imports の使い所
type
Post
outer_link
コードのテスト投稿:
import dynamic from 'next/dynamic';
import type Item from '@library/item';
const Component = dynamic(
() => {
return import('@library/item')
},
{ ssr: false }
) as typeof Item
- Type-Only Imports and Export:明示的に型のみ import / export ができる
- 純粋に型のみが import / export されるので副作用などが発生しない
Motivation
Before

After
