-
Notifications
You must be signed in to change notification settings - Fork 16
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
sharing types across client/server #42
Comments
trying to document it a bit better... shared-typesThere are types in the top level of the app in types/index.ts This is actually a package and there are links in the client to use it:
|
OK i removed namespaces, as it's not a JS feature and seems to be not recommended in typescript now. and i see how you're doing that adding the types to devDeps, so no need for the import. It's a bit of magic behind the scenes i wasn't following so added a bit of documentation in the types file |
OK this often seems to break, and I can't figure out why. maybe the types file is typescript and doesn't get injected into visual code correctly. in VSCode: neat as the 'magic types' is, it seems flaky so i'm gonna move to explicit imports. |
weirdly after working in this way for a while this error starts to show up:
CRA restriction: |
i had removed
|
sorry to keep harping on about this, it would be great to get it to work if you have more ideas.
|
i finally got around it. I was on my way to creating a published package but this method works with npm it will accept "@dcsan/typeroo": "../shared/typeroo", but it looks like (at least on the mac) this uses a symlink, which is what i was trying to get around for those windows people. not sure if yarn install does something different on windows... can't try it here.
|
Hi @dcsan so did you get your issue solved? This repo is a simple starter kit and there's definitely a lot to improve and I've been doing it gradually, so thanks for your impressions! |
I did find a fix that works but it's kind of a pain. it involves building the types I need in a local npm package, and then reinstalling it each time things change. working with a |
I wonder why But yeah, turning types into a npm package makes sense in my opinion, then you simply install the types in a similar way as when you install @types from Definitely Typed. |
not sure. i also wanted it to work for windows ppl so IDK how symlinks are handled there... |
I think the problem is that yarn uses this is all a problem cos create-react-app prevents you using files outside of current |
In this project I mentioned, there were some developers using Windows, they were actually the ones who decided to use symlinks to I imagine that it works just fine in Windows. And you're right, npm syntax is different, so it's either or. Have you considered making your types a package and using lerna to manage its usage within the repo? |
Lerna looks interesting but quite a heavyweight thing for just sharing a few definitions. |
Sounds reasonable. May I close this issue as there's no action to be taken in this repo at the moment? |
thanks for this boilerplate! Minimal but does the parts I needed.
I forked it and created a simple template based here, and started adding material-UI and a few things. https://github.com/dcsan/ts-mern
I hit this error:
I assume this is something to do with the shared types and the
types/index.d.ts
I tried instead creating my own Interface for
Item
and just usingItem
as the export and used type:https://github.com/dcsan/ts-mern/blob/master/types/AppTypes.ts
this works, but I'm not sure why your version didn't work...
The text was updated successfully, but these errors were encountered: