-
Notifications
You must be signed in to change notification settings - Fork 15
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
TypeScript support #5
Comments
It seems prismic is placing a low priority on this issue for some reason. Until WipeAir's PR gets accepted or primsic otherwise resolves this you can get types for this.$prismic by creating a prismic.d.ts file in your project and populating the following into it: import { getApi } from 'prismic-javascript'
import { DefaultClient } from 'prismic-javascript/d.ts/client'
import Vue from 'vue'
type ThenArg<T> = T extends Promise<infer U> ? U : T
type PrismicAPIPromise = ReturnType<typeof getApi>
type PrismicAPI = ThenArg<PrismicAPIPromise>
type ElementType =
| 'heading1'
| 'heading2'
| 'heading3'
| 'heading4'
| 'heading5'
| 'heading6'
| 'paragraph'
| 'preformatted'
| 'strong'
| 'em'
| 'list-item'
| 'o-list-item'
| 'group-list-item'
| 'group-o-list-item'
| 'image'
| 'embed'
| 'hyperlink'
| 'label'
| 'span'
type Elements = { [key in ElementType]: string }
type HTMLSerializer<T> = (type: ElementType, element: any, text: string | null, children: T[], index: number) => T
interface RichText {
Elements: Elements
asHtml(richText: any, linkResolver?: (doc: any) => string, serializer?: HTMLSerializer<string>): string
asText(richText: any, joinString?: string): string
}
interface Link {
url(link: any, linkResolver?: (doc: any) => string): string
}
interface VuePrismic {
endpoint: string
linkResolver: (doc: any) => string
htmlSerializer: HTMLSerializer<string>
client: DefaultClient
richTextAsPlain: (field: string) => string
}
type PrismicVue<T> = VuePrismic & T
declare module 'vue/types/vue' {
interface Vue {
$prismic: PrismicVue<PrismicAPI>
}
} I really like Prismic but I don't understand why proper typescript support is not a priority for them. |
Thanks for this. I just saw your PR from March too. I also rebuilt their Vue components. I'll see if I can get their support to nudge this along. |
Hi,
To use the NuxtJS prismic module I have to use it like |
I've changed type PrismicAPI to: |
I still feel like a beginner with typescript too but I am posting my solution anyway ;)
|
@lennartzellmer, this is awesome! I had to add the Predicates typings to mine. I just made a |
I extended my solution by those two lines to improve maintainability:
|
Hi! I recently noticed this long-lasting discussion and I'm glad to see you all figured out different ways to get the typing needed on your Vue.js projects. I admit, however, that this is still far from ideal; with Vue 3 having an emphasis on TypeScript I'll be looking forward to working on the new major of this kit using TypeScript to provide everyone with proper typing 🙂 (same goes for the @nuxtjs/prismic module) In the meantime I'll encourage you to use the solution proposed by @lennartzellmer #5 (comment), the interface is not expected to move any time soon. I'll check also with our product team if it's conceivable to add definitions for this version. |
Hey everyone, I hope your journey with Vue has been going well! I'm happy to announce to you all that we started working towards supporting Vue 3 and that we opened a Suggestion Thread for everyone to discuss feedback and improvements that could be made to this kit. As announced previously here providing proper TypeScript support will also be part of this update! Cheers! |
First-class TypeScript support has been added as part of our Vue 3 package: Our new development kits also follow this new guideline:
After thoughtful consideration, those changes won't be backported to Thank you all for your understanding and contributions. We hope you'll enjoy using Prismic with our new Vue 3-ready kit! |
The title mostly says it all. Type definitions for Prismic would be great for TypeScript projects. Sorry if this error is actually relates to
prismic-javascript
orprismic-dom
.The text was updated successfully, but these errors were encountered: