Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: Type error: Property 'char' does not exist on type 'SlotProps | undefined'. #3585

Open
2 tasks done
ritmillio opened this issue Apr 23, 2024 · 7 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@ritmillio
Copy link

Describe the bug

After installation of the input-otp component I am getting a build error in Next.js - using TypeScript.

The error occurs here: const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index];

Property 'char' does not exist on type 'SlotProps | undefined'.ts(2339)
Property 'hasFakeCaret' does not exist on type 'SlotProps | undefined'.ts(2339)
Property 'isActive' does not exist on type 'SlotProps | undefined'.ts(2339)

Affected component/components

Input OTP

How to reproduce

Install input-otp.

Setup eslint:
eslintrc.cjs:

/** @type {import("eslint").Linter.Config} */
const config = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: true,
  },
  plugins: ["@typescript-eslint"],
  extends: [
    "next/core-web-vitals",
    "plugin:@typescript-eslint/recommended-type-checked",
    "plugin:@typescript-eslint/stylistic-type-checked",
  ],
  rules: {
    // These opinionated rules are enabled in stylistic-type-checked above.
    // Feel free to reconfigure them to your own preference.
    "@typescript-eslint/array-type": "off",
    "@typescript-eslint/consistent-type-definitions": "off",

    "@typescript-eslint/consistent-type-imports": [
      "warn",
      {
        prefer: "type-imports",
        fixStyle: "inline-type-imports",
      },
    ],
    "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
    "@typescript-eslint/require-await": "off",
    "@typescript-eslint/no-misused-promises": [
      "error",
      {
        checksVoidReturn: { attributes: false },
      },
    ],
  },
};

module.exports = config;

Codesandbox/StackBlitz link

No response

Logs

./src/components/core/ui/input-otp.tsx:39:11
Type error: Property 'char' does not exist on type 'SlotProps | undefined'.

  37 |   const inputOTPContext = React.useContext(OTPInputContext);
  38 |
> 39 |   const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index];
     |           ^
  40 |
  41 |   return (
  42 |     <div
 ELIFECYCLE  Command failed with exit code 1.

System Info

package.json

"next": "^14.1.4",
"@types/eslint": "^8.56.2",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"eslint": "^8.56.0",
"eslint-config-next": "^14.1.0",
"typescript": "^5.4.3",

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@ritmillio ritmillio added the bug Something isn't working label Apr 23, 2024
@rtorcato
Copy link

this will fix it.

const { char, hasFakeCaret, isActive } = inputOTPContext.slots[
    index
  ] as SlotProps

@ritmillio
Copy link
Author

this will fix it.

const { char, hasFakeCaret, isActive } = inputOTPContext.slots[
    index
  ] as SlotProps

I have the following error with this solution:

Use a ! assertion to more succinctly remove null and undefined from the type.eslint@typescript-eslint/non-nullable-type-assertion-style

@guilhermerodz
Copy link

hey @ritmillio input-otp maintainer here 👋🏻

could not reproduce it locally.

can you provide a stackblitz?

@keeandev
Copy link

Ran into the same issue today, fresh install from shadcn.

@keeandev
Copy link

Ran into the same issue today, fresh install from shadcn.

I reinstalled my project with PNPM instead of Bun, problem solved.

@ritmillio
Copy link
Author

ritmillio commented May 1, 2024

Hey, @guilhermerodz

Here's a minimum reproduction of my use-case: https://stackblitz.com/edit/stackblitz-starters-9avgfk?file=src%2Fcomponents%2Fui%2Finput-otp.tsx

@keeandev - I am using pnpm but reinstalling didn't solve my problem

@keeandev
Copy link

keeandev commented May 1, 2024

Hey, @guilhermerodz

Here's a minimum reproduction of my use-case: https://stackblitz.com/edit/stackblitz-starters-9avgfk?file=src%2Fcomponents%2Fui%2Finput-otp.tsx

@keeandev - I am using pnpm but reinstalling didn't solve my problem

Apologies, I had a very similar issue, but I solved this issue by putting an exclamation mark at the end of the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants