codesandbox / codesandbox/codesandbox-client
Strange TypeScript error: Cannot read properties of undefined
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13.6k
- Forks
- 2.4k
- Avg merge
- 6d 19h
- Merged PRs (30d)
- 2
Description
🐛 bug report
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project
adheres to. - I have searched the issue tracker for an issue that matches the one I want
to file, without success.
Description of the problem
As the title states, I see this TypeScript error in CodeSandbox, which isn't reproducible in TS Playground: https://www.typescriptlang.org/play?ssl=5&ssc=3&pln=1&pc=1#code/KYDwDg9gTgLgBDAnmYcCqBnYARCBjAVwFtgA7GAFQEsYAbYAYQAsBDUgc2AHkwYqJSGOAF44AbwBQcOADMqUDJRr0A-AC44iqFQ4BuKZuB4BAE2p1g6zTG16DOmMCgA3FrSuliAIyf6AvvoGoJCwcMaC8ARYuIQk5Ob0zGycAKIyMkbwogAUktJyCkoWInAARAASwLS0EKUANAZY4WbKqKKlAOrQtCYAhPX25E6utCUAjAAMUxJ+Gpg4+MRkRYmsHNy8-IIAlCIAfOIS4RgQ9AB0NezZAOQ0cADu0ADWGNfbM7pAA
I also don't get the error in my local Visual Studio Code.
How has this issue affected you? What are you trying to accomplish?
I'd like to set default values for properties passed to my hook. Somehow TypeScript in the CodeSandbox environment doesn't like that syntax even though it is valid TypeScript. Not sure what is going on.
To Reproduce
See this sandbox:
Link to sandbox: https://codesandbox.io/s/newline-custom-react-hooks-with-typescript-5rcdvu?file=/src/hooks/useDocumentTitleChangeEffect.ts
Your Environment
| Software | Name/Version |
|---|---|
| Сodesandbox | 2bfc25146 |
| Browser | Chrome |
| Operating System | macOS |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the linked CodeSandbox and inspect src/hooks/useDocumentTitleChangeEffect.ts, then compare its TypeScript setup with the provided TypeScript Playground and local Visual Studio Code behavior. Reproduce the error and identify the environment difference; done means the valid default-property syntax no longer produces the unexpected error in CodeSandbox.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100