質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

1回答

1300閲覧

TypeScriptのエラーについて

hayatoganbaru

総合スコア7

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2021/12/14 22:51

編集2021/12/15 00:23

こんにちは。
TypeScriptをUdemyで学習中の初心者です。
こんな下記のエラーが発生しました。
イメージ説明
直訳してみて、プロパティの'unregister'はタイプ'UseDescendantsReturn'に存在しませんという意味だと捉えました。
「TS2339 エラー」でググってみましたが、エラーを解消するヒントは得られませんでした。
'unregister'なんて記述はした覚えが全くないので困っています。
解決へのアプローチをお教え頂けないでしょうか?

unregisterの記載場所と詳細

node_modules/@chakra-ui/descendant/src/use-descendant.tsに記述があるとのことです。

実際にそのファイルは以下のようになっております。
エラー箇所のような記述を私は見つけることができませんでした。

import { createContext, mergeRefs } from "@chakra-ui/react-utils" import { RefCallback, useRef, useState } from "react" import { DescendantsManager, DescendantOptions } from "./descendant" import { useSafeLayoutEffect, cast } from "./utils" /** * @internal * React hook that initializes the DescendantsManager */ function useDescendants<T extends HTMLElement = HTMLElement, K = {}>() { const descendants = useRef(new DescendantsManager<T, K>()) useSafeLayoutEffect(() => { return () => descendants.current.destroy() }) return descendants.current } export interface UseDescendantsReturn extends ReturnType<typeof useDescendants> {} /* ------------------------------------------------------------------------------------------------- * Descendants context to be used in component-land. - Mount the `DescendantsContextProvider` at the root of the component - Call `useDescendantsContext` anywhere you need access to the descendants information NB: I recommend using `createDescendantContext` below * -----------------------------------------------------------------------------------------------*/ const [ DescendantsContextProvider, useDescendantsContext, ] = createContext<UseDescendantsReturn>({ name: "DescendantsProvider", errorMessage: "useDescendantsContext must be used within DescendantsProvider", }) /** * @internal * This hook provides information a descendant such as: * - Its index compared to other descendants * - ref callback to register the descendant * - Its enabled index compared to other enabled descendants */ function useDescendant<T extends HTMLElement = HTMLElement, K = {}>( options?: DescendantOptions<K>, ) { const descendants = useDescendantsContext() const [index, setIndex] = useState(-1) const ref = useRef<T>(null) useSafeLayoutEffect(() => { return () => { if (!ref.current) return descendants.unregister(ref.current) } }, []) useSafeLayoutEffect(() => { if (!ref.current) return const dataIndex = Number(ref.current.dataset.index) if (index != dataIndex && !Number.isNaN(dataIndex)) { setIndex(dataIndex) } }) const refCallback = options ? cast<RefCallback<T>>(descendants.register(options)) : cast<RefCallback<T>>(descendants.register) return { descendants, index, enabledIndex: descendants.enabledIndexOf(ref.current), register: mergeRefs(refCallback, ref), } } /* ------------------------------------------------------------------------------------------------- * Function that provides strongly typed versions of the context provider and hooks above. To be used in component-land * -----------------------------------------------------------------------------------------------*/ export function createDescendantContext< T extends HTMLElement = HTMLElement, K = {} >() { type ContextProviderType = React.Provider<DescendantsManager<T, K>> const ContextProvider = cast<ContextProviderType>(DescendantsContextProvider) const _useDescendantsContext = () => cast<DescendantsManager<T, K>>(useDescendantsContext()) const _useDescendant = (options?: DescendantOptions<K>) => useDescendant<T, K>(options) const _useDescendants = () => useDescendants<T, K>() return [ // context provider ContextProvider, // call this when you need to read from context _useDescendantsContext, // descendants state information, to be called and passed to `ContextProvider` _useDescendants, // descendant index information _useDescendant, ] as const }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2021/12/14 22:53

> 'unregister'なんて記述はした覚えが全くないので困っています。 提示のコードは、どのファイルに書かれているものでしょうか?
hayatoganbaru

2021/12/14 23:08

早い返信ありがとうございます。 質問を編集して追加しました。 ご確認いただければ幸いです。
guest

回答1

0

functionuseDescendantのスコープ内に以下の記述が見受けられるのですが、エラー箇所はこれではないでしょうか?

useSafeLayoutEffect(() => { return () => { if (!ref.current) return descendants.unregister(ref.current) // <- method unregister() } }, [])

行数もエラー箇所の54あたりなので間違ってはないと思うのですが。

投稿2022/01/03 11:53

wsb

総合スコア194

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問