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.

Typescript prop errors

See original GitHub issue

Running into some type issues but a basic button that has props passed through Button_tsx_—_template

I’m using the default next.js typescript configuration

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kyhcommented, Sep 4, 2021

Using type instead of an interface works

0reactions
good-ideacommented, Nov 18, 2021

This appears to be an issue with newer versions of Typescript (4.5+) - I’m not seeing this error on 4.3.2. TS 4.5 has a new feature, “Template String Types as Discriminants”, so it’s now parsing this:

declare type TransientProps = Record<`$${string}`, any>;

In a smarter way. Unfortunately, for those of us using interfaces, those aren’t working because interfaces cannot extend records with templated keys. Immediate solutions are:

  • convert your props interfaces to types
  • extend your interfaces with TransientProps

Solutions for the lib:

  • Update the definition of TransientProps to:
    declare type TransientProps = Record<`$${string}` | string, any>;
    
    (adding that | string to the key)
  • Or, just remove the TransientProps definition completely:
    • From a type-checking point of view, does this achieve anything special?
Read more comments on GitHub >

github_iconTop Results From Across the Web

React component throwing TypeScript error for function ...
The first param to Component type is props type , and you have not defined it, therefore the error. Define a interface,
Read more >
Error Boundaries - React TypeScript Cheatsheets
Option 1: Using react-error-boundary. ... class ErrorBoundary extends Component<Props, State> { public state: State = { hasError: false } ...
Read more >
Typescript suddenly started to error on missing props for many ...
It failed with an error regarding missing props on many Drei components. I'm fairly sure that I didn't change anything else and these...
Read more >
React & TypeScript
You will get the following TypeScript error. Property 'name' is missing in type '{}' but required in type 'Props'.
Read more >
Documentation - JSX - TypeScript
As the name suggests, the component is defined as a JavaScript function where its first argument is a props object. TS enforces that...
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