OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

WordPress block development TypeScript - useSelect type error

  • Thread starter Thread starter codewithfeeling
  • Start date Start date
C

codewithfeeling

Guest
I'm trying to use useSelect with TypeScript to get the current post type. In regular JavaScript, this code works fine (and is in fact code used in the main Gutenberg repo):

Code:
const postType = useSelect(
    ( select ) => select( 'core/editor' ).getCurrentPostType(),
    []
);

However, when I convert to TypeScript, this throws a type error:

Code:
Property 'getCurrentPostType' does not exist on type 'never'.ts(2339)

I can't see what's causing it, why the return type is <never>.

The code actually does work and compiles fine, but I would like to get it type safe. Any ideas on how I can resolve this would be much appreciated.
<p>I'm trying to use <code>useSelect</code> with TypeScript to get the current post type. In regular JavaScript, this code works fine (and is in fact code used in the main Gutenberg repo):</p>
<pre class="lang-js prettyprint-override"><code>const postType = useSelect(
( select ) => select( 'core/editor' ).getCurrentPostType(),
[]
);
</code></pre>
<p>However, when I convert to TypeScript, this throws a type error:</p>
<pre><code>Property 'getCurrentPostType' does not exist on type 'never'.ts(2339)
</code></pre>
<p>I can't see what's causing it, why the return type is <code><never></code>.</p>
<p>The code actually does work and compiles fine, but I would like to get it type safe. Any ideas on how I can resolve this would be much appreciated.</p>
Continue reading...
 

Latest posts

A
Replies
0
Views
1
Aarif Hussain A Nassar
A
F
Replies
0
Views
1
Fahmi Nur Fachrurozi
F
Top