# Type definitions for params and previewData

**URL:** https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717
**Category:** Developing with Prismic
**Created:** [November 16, 2022, 4:29pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717 "2022-11-16T16:29:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![frank.stallone](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/frank.stallone/32/4834_2.png) [@frank.stallone](https://community.prismic.io/u/frank.stallone)
#### Post date: [November 16, 2022, 4:29pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717/1 "2022-11-16T16:29:38Z")

</div>

I am coming back to this code I wrote and not happy with for obvious `any` reasons.

```auto
export async function getStaticProps({ params, previewData }: any) {
  const client = createClient({ previewData });

  const { uid, lang } = params;

  const page = await client.getByUID('components', uid, { lang });

  return {
    props: {
      page,
    },
  };
}

```

Where can I grab the Typescript definitions for `params` and `previewData`? Not finding this documentation or community members talking about it here.I could use Next.js's `GetStaticProps` but if I do that the destructuring line `const { uid, lang } = params;` has errors presumably because they are from Prismic not Next.js

---

<div class="post-metadata">

### Author: ![devteam2](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@devteam2](https://community.prismic.io/u/devteam2)
#### Post date: [November 22, 2022, 6:42pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717/2 "2022-11-22T18:42:36Z")

</div>

I also am having a problem with the type definition for the previewData. Maybe someone has an answer for this. Thanks!

---

<div class="post-metadata">

### Author: ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)
#### Post date: [November 24, 2022, 2:44pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717/5 "2022-11-24T14:44:53Z")

</div>

Hi @frank.stallone @devteam2

Thanks for reaching out.

I have reached out to the dev team regarding those TypeScript questions, and here is what we think about it.

- Typing `params`:

We have a new “Next.js: TypeScript” guide that covers what you are asking.  
[Use TypeScript with Next.js - Documentation - Prismic](https://prismic.io/docs/typescript-nextjs#typing-page-componentsNote) the use of Next.js’s `GetStaticPropsContext.`

The second code block shows how to use `GetStaticPropsContext` with a typed `params` object.

- Typing `previewData`

Preview data can be anything, depending on the visitor, so it may not be a good idea to type the data manually.

Instead, runtime validation should occur, where you check the object for the property you need before using it.

That being said, `GetStaticPropsContext`’s second type parameter allows someone to define `previewData`’s type.

```auto

type MyPreviewData = {
 // Your data here foo: "bar" 
} 
type PageParams = {
 uid: string
} 

export function getStaticProps({ params, previewData }: GetStaticPropsContext<PageParams, MyPreviewData>) { 
  // ... 
}

```

When using `@prismicio/next` and its `enableAutoPreviews()` function, you do not need to type `previewData` manually.

Our recommended setup uses `enableAutoPreviews()`: [Set up Prismic with Next.js - Documentation - Prismic](https://prismic.io/docs/setup-nextjs#configure-prismic)

Please let us know if need any further clarification,  
Best

---

<div class="post-metadata">

### Author: ![frank.stallone](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/frank.stallone/32/4834_2.png) [@frank.stallone](https://community.prismic.io/u/frank.stallone)
#### Post date: [November 25, 2022, 6:08pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717/6 "2022-11-25T18:08:44Z")

</div>

Thank you for the response and it's great the docs have been updated!! Although `GetStaticPropsContext` works for the `previewData`, take a look at the following error I get for `uid` and `lang`...

 ![CleanShot 2022-11-25 at 13.06.32@2x](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/c/c768e7ef7da9c0669034bbbffbd311f512c5cc58.png)

`Property 'uid' does not exist on type 'ParsedUrlQuery | undefined'.ts(2339)`

I have not found a way around this. Please advise!

---

<div class="post-metadata">

### Author: ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)
#### Post date: [November 30, 2022, 4:01pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717/7 "2022-11-30T16:01:45Z")

</div>

I'm gathering some information and I will get back to you as soon as possible.

---

<div class="post-metadata">

### Author: ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)
#### Post date: [December 2, 2022, 5:34pm UTC](https://community.prismic.io/t/type-definitions-for-params-and-previewdata/11717/8 "2022-12-02T17:34:06Z")

</div>

Hi @frank.stallone ,

**ParsedUrlQuery** should only appear if an explicit type parameter for **params** was not given (note the lack of \<...\> after **GetStaticPropsContext** :

```auto
export async function getStaticProps({ params }:GetStaticPropsContext) {
        **params**
        // ^ typed as ParsedUrlQuery
}

```

Here’s what it should look like in order to type params:

```auto
type PageParams = {
        uid: string
}

```

```auto
export async function getStaticProps({ params }:GetStaticPropsContext<PageParams>) {
        params
        // ^ typed as PageParams
}

```
