question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type Error in @headlessui/react

See original GitHub issue

I am trying to use Headless UI Select component in a Chrome extension & it gives error: ReferenceError: process is not defined as process.nextTick is used.

Is there anyway I can bypass that as process is not available in Chrome extensions I think? Or maybe can you guys polyfill it? Or I am just a minority.

Edit: I couldn’t find process.nextTick being used 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
RobinMalfaitcommented, Jan 8, 2021

Hey! Thank you for your bug report! Much appreciated! 🙏

The TypeScript error that you are receiving is a known issue that has been fixed but not fully released yet. However, if you do want to make use of the fix, try using the dev build: yarn add @headlessui/react@dev or npm install @headlessui/react@dev.

Yeah the process issue can’t be ours, because we don’t use process inside the components 😅

1reaction
deadcoder0904commented, Jan 1, 2021

Here’s my Select component that doesn’t work:

Select.tsx

interface IProps {
	label?: string
	options: Array<{
		id: number
		name: string
	}>
}

export const Select = ({ label, options }: IProps) => {
	const [selectedOption, setSelectedOption] = React.useState(options[0])

	return (
		<Listbox value={selectedOption} onChange={setSelectedOption}>
			<Listbox.Button>{selectedOption.name}</Listbox.Button>
			<Listbox.Options>
				{options.map((option) => (
					<Listbox.Option key={option.id} value={option}>
						{option.name}
					</Listbox.Option>
				))}
			</Listbox.Options>
		</Listbox>
	)
}

I get this error (red-squiggly line) on value of value={option}:

Type ‘{ id: number; name: string; }’ is not assignable to type ‘(string & { id: number; name: string; }) | (number & { id: number; name: string; }) | (readonly string[] & { id: number; name: string; })’. Type ‘{ id: number; name: string; }’ is not assignable to type ‘readonly string[] & { id: number; name: string; }’. Type ‘{ id: number; name: string; }’ is missing the following properties from type ‘readonly string[]’: length, concat, join, slice, and 16 more.

I even tried doing value={option.name} but then the select element gets removed from DOM.

App.tsx

const shapes = [
	{
		id: 1,
		name: 'Circle',
	},
	{
		id: 2,
		name: 'Square',
	},
]

<Select label="Shape" options={shapes} />

And the one that works has const shapes = ['Circle', 'Square'] & respective changes in Select.tsx 😃

The weird thing is the one that doesn’t work in Chrome extension works in Codesandbox → https://codesandbox.io/s/headlessuireact-listbox-example-forked-lbct7?file=/src/App.js

And now the error ReferenceError: process is not defined is gone. It only hides the Select box entirely from the DOM after 1st selection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Error for `Dialog.Panel`: ts(2339) · Issue #1419 - GitHub
A restart/reload of VS Code should do the same thing. Here is a very basic CodeSandbox with React, TypeScript and Headless UI proving...
Read more >
typescript errors when using headless ui documentation
From what I understand, React.forwardRef takes two type params. The RefType and the Props Type (backwards from the function params, (props, ...
Read more >
Listbox (Select) - Headless UI
For example, the Listbox.Option component exposes an active state, which tells you if the option is currently focused via the mouse or keyboard,...
Read more >
How to Use the Dialog Component with Headless UI and ...
Tailwind CSS is one of the most popular options when it comes to styling React applications. You can easily add styles to your...
Read more >
TypeError: undefined is not iterable (cannot read property ...
I have made a project close to Instagram using nextjs and headless UI with javascript. When I installed tsconfig to transfer the project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found