Git Product home page Git Product logo

Comments (7)

veu avatar veu commented on May 30, 2024 5

@BernardHymmen To generate types for v10 you need to add the --v10 or -X option. That will create the new EntrySkeleton format and you’re good to go.

from cf-content-types-generator.

SimonyanGrno avatar SimonyanGrno commented on May 30, 2024 2

@BernardHymmen I've used uppercase X and everything works fine

from cf-content-types-generator.

veu avatar veu commented on May 30, 2024

Hi, we do need a bit more info to help you out.

  • What were you trying to do when you got the error?
  • What does your setup look like? Especially, which flags were you using for the type generator?
  • What does <Generated Type> look like?

from cf-content-types-generator.

BernardHymmen avatar BernardHymmen commented on May 30, 2024

I just ran into the exact same issue. This is my first time trying to do type generation for Contentful objects so I was just gettting started and following the steps laid out in this very nice blog post

https://www.seancdavis.com/posts/generating-workable-typescript-types-from-contentful-content/

There's no date on that post (boo!), but it looks like the embedded video was uploaded in early May, FWIW. Anyway, don't recall making any changes to what the post describes, other than consolidating it all into a single npm script like so:

    "contentful-export": "contentful space export --config contentful/export-config.json --management-token %CONTENTFUL_MANAGEMENT_PAT% --space-id %CONTENTFUL_SPACE_ID%",
    "contentful-typegen": "cf-content-types-generator contentful/export.json --out types/contentful",
    "contentful-update": "npm run contentful-export && npm run contentful-typegen"

Other than that, the post describes my setup and process accurately. I've got a pre-build.cmd script that I run as part of my build to automatically update my Contentful models for both my C# and (hopefully soon) TypeScript types. Here's the command for the TypeScript part of it:

call npm run contentful-update

This process generates a JSON schema file that looks just fine to my casual eye, and the TypeScript type definitions all look fine too...except for the red squiggles in VSCode on the type parameter in every instance of Entry<T>. Here's an example of one of my objects...

import type { Asset, Entry, EntryFields } from "contentful";
import type { TypePersonFields } from "./TypePerson";

export interface TypeBlogPostFields {
    title: EntryFields.Symbol;
    slug: EntryFields.Symbol;
    heroImage?: Asset;
    description: EntryFields.Text;
    body?: EntryFields.Text;
    author?: Entry<TypePersonFields>;  // <== squiggles on TypePersonFields
    publishDate: EntryFields.Date;
    project?: Entry<Record<string, any>>[];  // <== squiggles on Record<string, any>
}

export type TypeBlogPost = Entry<TypeBlogPostFields>; // <== squiggles on TypeBlogPostFields

All the error messages are versions of

Type 'TypePersonFields' does not satisfy the constraint 'EntrySkeletonType'.
Type 'TypePersonFields' is missing the following properties from type 'EntrySkeletonType': fields, contentTypeId ts(2344)

Here are the various package versions I'm using:

dependencies
    "contentful": "^10.2.3",
    "contentful-cli": "^2.6.22",

devDependencies
    "cf-content-types-generator": "^2.12.2",
    "typescript": "^4.7.4"

from cf-content-types-generator.

BernardHymmen avatar BernardHymmen commented on May 30, 2024

@veu - Thanks for your help! Yes, adding the --v10 option did the trick for me. Yay!

I thought you might want to know that, curiously, the -x option threw an error for me. Here's what I got:

> cf-content-types-generator contentful/export.json -x --out types/contentful

 »   Error: Unexpected argument: -x
 »   See more help with --help

from cf-content-types-generator.

BernardHymmen avatar BernardHymmen commented on May 30, 2024

@SimonyanGrno - D'OH! All the other arguments are lowercase and I failed to notice that -X is, in fact, uppercase. <FacePalm/> Yes, it worked just fine when I switched it to uppercase. Thanks for pointing this out!

from cf-content-types-generator.

marcolink avatar marcolink commented on May 30, 2024

This issue seems to be solved - will close for now

from cf-content-types-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.