Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typescript Circular properties causing typed Any#1879

Unanswered
sethdumaguin asked this question inGeneral
Discussion options

Hi!

I am trying to develop some type of Folder structures where I defined these three entities:

File: the files in a folder,
FolderItem: the items that can be in a folder, which is a union ofFile andFolder since a folder can have both.
Folder: a folder that holdsFolderItem.

The problem that I am seeing is the circular dependency here is causingFolder andFolderItem to be typed as any. I was wondering if there's a way to go around this. Here is a codesandbox link:https://codesandbox.io/s/little-monad-oim34o?file=/src/Folder.ts.

I appreciate the help!

You must be logged in to vote

Replies: 1 comment

Comment options

Hi@sethdumaguin!

I don't see an obvious solution in your example, butthis part of the documentation andthis neat trick by kresli might give some inspiration.

import{IAnyModelType,Instance,types}from"mobx-state-tree";constNode=types.model({x:5,me:types.maybe(types.late(():IAnyModelType=>Node))}).views((self)=>({getMe(){returnself.measInstance<typeofself>|undefined;}}));constnode=Node.create({x:5,me:{x:4}});constme=node.getMe();// Works!me?.x// Property 'y' does not exist on type...me?.y
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@sethdumaguin@EmilTholin

[8]ページ先頭

©2009-2025 Movatter.jp