0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

react-primitivesのTypeScript型定義ファイルをつくる

Posted at

TypeScriptを採用しているプロジェクトでreact-primitivesを使ってみた。

react-primitivesの型ファイルをinstallしようとしたが、ないと怒られた。

(๑•﹏•) < npm install --save-dev @types/react-primitives
npm ERR! code E404
npm ERR! 404 Not Found: @types/react-primitives@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     ごちゃごちゃ
(#°﹏°) <

ちなみに@なしでやってもダメって言われた。

(๑•﹏•) < npm install --save-dev types/react-primitives
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/types/react-primitives.git
npm ERR!
npm ERR! ERROR: Repository not found.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     ごちゃごちゃ
(#°﹏°) <

ここから本題

ナイスなissueがあったので、それに従ってみた。 => https://github.com/lelandrichardson/react-primitives/issues/82

src配下に以下のようにディレクトリをきって、index.d.tsファイルを作成する

src/@types/react-primitives/index.d.ts

index.d.ts
declare module 'react-primitives' {
  export {
    StyleSheet,
    View,
    Text,
    Image,
    Touchable,
    Animated,
  } from 'react-native'
}

ファイル置いておけば自動で認識して解決してくれる。

所感

今回はreact-nativeから流用できたから楽だった。

こういうケースは他のライブラリでも多いと思うが、tsconfig.json"skipLibCheck": trueして無視してしまうのが一般的なんだろうか。どうなんでしょう。

以上、ありがとうございました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?