Closed angeloashmore closed 2 years ago
Path | Size |
---|---|
dist/index.js | 1.07 MB (+0.01% 🔺) |
dist/index.cjs | 1.08 MB (+0.02% 🔺) |
Thanks for the review, @lihbr!
I'll leave the PR open until we test these changes in the pending Slice Machine integration (see this related PR).
Merging #28 (89a2806) into main (e61a328) will increase coverage by
0.24%
. The diff coverage is92.30%
.
@@ Coverage Diff @@
## main #28 +/- ##
==========================================
+ Coverage 90.50% 90.75% +0.24%
==========================================
Files 21 21
Lines 337 346 +9
Branches 82 86 +4
==========================================
+ Hits 305 314 +9
Misses 4 4
Partials 28 28
Impacted Files | Coverage Δ | |
---|---|---|
src/generateTypes.ts | 97.43% <92.30%> (+0.76%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
Types of changes
Description
This PR adds the ability to generate a
Content
namespace in the@prismicio/client
module. TheContent
namespace allows a developer to easily access generated document and Slice types from a centralized, consistent import path. All document and Slice types are exported from theContent
namespace.Without this PR, developers need to import types manually directly from the generated file. The relative location of the type file changes based on the consuming file, requiring additional thought to resolve. Relative imports also makes code generation outside
prismic-ts-codegen
(e.g. Slice Machine) more difficult.The following code shows a simplified version of the generated
Content
output:The following example shows how a Slice's React component could be typed using the
Content
namespace:All document and Slice types will continue to be exported from the generated file as a top-level export (i.e. they are accessible outside the
@prismicio/client
module).Note: Automatic
@prismicio/client
typing is unaffected by this newContent
namespace. The features are similar in that they more easily let a developer make use of the generated content types. Projects are likely to use both integrations.CLI changes
The CLI will generate the
Content
namespace by default.It can be disabled by setting
clientIntegration.includeContentNamespace
tofalse
inprismicCodegen.config.ts
.generateTypes()
changesThe
generateTypes()
function will not generate theContent
namespace by default.It can be enabled by setting
clientIntegration.includeContentNamespace
totrue
.Checklist:
🦚