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.

@chakra-ui/descendant fails TypeScript strict type-checking, breaking CI

See original GitHub issue

Description

When using chakra-ui in a project with noPropertyAccessFromIndexSignature enabled (a strict type-checking option in tsconfig.json), @chakra-ui/descendant causes tsc to fail and complain due to two easily fixable errors

Link to Reproduction

https://www.npmjs.com/package/@chakra-ui/cra-template-typescript

Steps to reproduce

  1. Clone any chakra-ui project/template (npx create-react-app issue-chakra-types --template @chakra-ui/typescript)
  2. Add "noPropertyAccessFromIndexSignature": true to tsconfig.json->compilerOptions
  3. Have tsc check types, f.e. with a package.json script ("check": "tsc")
  4. Watch tsc cry about two minor mistakes:
node_modules/@chakra-ui/descendant/src/descendant.ts:64:31 - error TS4111: Property 'index' comes from an index signature, so it must be accessed with ['index'].

64       descendant.node.dataset.index = descendant.index.toString()
                                 ~~~~~

node_modules/@chakra-ui/descendant/src/use-descendant.ts:60:50 - error TS4111: Property 'index' comes from an index signature, so it must be accessed with ['index'].

60     const dataIndex = Number(ref.current.dataset.index)
                                                    ~~~~~

Chakra UI Version

1.7.3

Browser

Node 17.3.0 / TS 4.5.4

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

Perhaps do some CI checks with a strict tsconfig.json: 😉

"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied `any` type.. */,
"strictNullChecks": true /* When type checking, take into account `null` and `undefined`. */,
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
"strictBindCallApply": true /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */,
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
"noImplicitThis": true /* Enable error reporting when `this` is given the type `any`. */,
"useUnknownInCatchVariables": true /* Type catch clause variables as 'unknown' instead of 'any'. */,
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
"noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
"noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
"noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type */,

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
bkiaccommented, Feb 28, 2022

DOM and DOM.Iterable were missing from my compilerOptions.lib, adding them resolved the compilation issue

2reactions
bkiaccommented, Feb 28, 2022

does your compilerOptions in tsConfig contain "skipLibCheck": true,? if not, this should be enabled. the code itself is fine

This issue still persists in 1.8.1, skipLibCheck only skips declaration files

My error is with descendant.ts:

ui:typecheck: $ tsc --noEmit
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/descendant.ts(42,32): error TS2345: Argument of type 'T | DescendantOptions<K>' is not assignable to parameter of type 'T | null'.
ui:typecheck:   Type 'DescendantOptions<K>' is not assignable to type 'T | null'.
ui:typecheck:     Type 'DescendantOptions<K>' is not assignable to type 'T'.
ui:typecheck:       'DescendantOptions<K>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'HTMLElement'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/descendant.ts(60,39): error TS2304: Cannot find name 'Node'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/descendant.ts(64,23): error TS2339: Property 'dataset' does not exist on type 'T'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/descendant.ts(109,57): error TS2339: Property 'isSameNode' does not exist on type 'T'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/use-descendant.ts(60,42): error TS2339: Property 'dataset' does not exist on type 'T'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(7,34): error TS2304: Cannot find name 'Node'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(12,17): error TS2552: Cannot find name 'Node'. Did you mean 'nodes'?
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(13,17): error TS2552: Cannot find name 'Node'. Did you mean 'nodes'?
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(20,17): error TS2552: Cannot find name 'Node'. Did you mean 'nodes'?
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(21,17): error TS2552: Cannot find name 'Node'. Did you mean 'nodes'?
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(28,17): error TS2552: Cannot find name 'Node'. Did you mean 'nodes'?
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(29,17): error TS2552: Cannot find name 'Node'. Did you mean 'nodes'?
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(39,64): error TS2304: Cannot find name 'Node'.
ui:typecheck: ../../node_modules/@chakra-ui/descendant/src/utils.ts(54,10): error TS2304: Cannot find name 'window'.
ui:typecheck: error Command failed with exit code 2.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog - Chakra UI
When the Chakra CLI fails to generate theme typings, it now exits with a status code of 1 . This resolves an issue...
Read more >
typescript Code Example - Code Grepper
TypeScript is a programming language developed and maintained by Microsoft.
Read more >
@material-ui/types | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
target/npmlist.json · 1-local-storage · IT2810 H21 / Team 06 ...
{"name":"react-prosjekt","version":"0.1.0","dependencies":{"@chakra-ui/icons":{"version":"1.0.15" ...
Read more >
Release Notes — Airflow Documentation
In order to make airflow dags test more useful as a testing and debugging tool, we no longer run a backfill job and...
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