Closed delucis closed 4 years ago
I think the package.json files generated for core, multiplayer etc. should include a types field pointing to the correct place for general consumption
You're right. The fix is relatively straightforward:
packages/*.js
to TS.After this, dist/types/packages
will contain one *.d.ts for each subpackage.
scripts/proxy-dirs.js
to add a types field to the package.json.About where to expose base.ts
, I think an internal
package sounds good.
Try v0.39.2
.
Async
should be available in boardgame.io/internal
. Not every sub-package will have types (client
, for example) because we haven't converted the relevant source files to TS.
👍 From a quick check, it looks like it works as expected for packages that have been converted, but not for server
. What’s the reason for the server
sub-package being provided differently from the other sub-packages?
The other thing that would be handy would be to be able to access the basic types defined in src/types.ts
. Maybe the types
field in boardgame.io’s top-level package.json could point to ./dist/types/src/types.d.ts
and then those could be imported directly from boardgame.io:
import type { State } from 'boardgame.io'
I can look into a setting up a I see now that you’ve already exposed server-internal
sub-package.Async
in boardgame.io/internal
. Perfect.
I cannot find any way to access types and interfaces like PhaseConfig
from src/types.ts
. Can they also be included?
EDIT: Nevermind, I found them under boardgame.io/dist/types/src/types
.
@janKir They’re currently there, but hopefully in the next patch they’ll be available from a more obvious path. Types were only added a few hours ago!
Thanks! Yes, I just stumbled across this library earlier today when the latest release did not include any types, yet... :D Keep up the great work!
What’s the reason for the server sub-package being provided differently from the other sub-packages?
A good reason might have existed in the past, but I can't think of a reason why we do it differently now.
@nicolodavis Following on from https://github.com/nicolodavis/boardgame.io/issues/573#issuecomment-603237109
For now, the bundle doesn’t include a
boardgame.io/types
package, so I can’t doI found the base database type by doing this, but that seems pretty fragile:
I’m not familiar yet with how best to expose and bundle types. I think the
package.json
files generated forcore
,multiplayer
etc. should include atypes
field pointing to the correct place for general consumption (TS docs).Then when someone does
import X from 'boardgame.io/X'
Typescript will also know where to find the types for that module. (The server module doesn’t currently follow this pattern, so it might need a different approach?)I’m also not sure what’s the nicest way to expose
base.ts
(because it’s not part of the main public-facing API), but I think it and all the related types should be somewhere like aserver-internals
package like theinternal
package, so database connectors can use them cleanly. (TheAsync
abstract class is not only its types, because it actually provides functionality.)