Skip to content
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

feat: improve types #47

Merged
merged 6 commits into from Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -52,6 +52,28 @@ export default {
}
```

### Typescript setup

Add the types to your "types" array in tsconfig.json after the `@nuxt/types` entry.

:warning: Use `@nuxt/vue-app` instead of `@nuxt/types` for nuxt < 2.9.

**tsconfig.json**

```json
{
"compilerOptions": {
"types": [
"@nuxt/types",
"@nuxtjs/moment"
]
}
}
```
> **Why?**
>
> For typescript to be aware of the additions to the `nuxt Context`, the `vue instance` and the `vuex store`, the types need to be merged via [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) by adding `@nuxtjs/moment` to your types.

## Configuration

To strip all locales except `en`:
Expand Down
15 changes: 11 additions & 4 deletions types/index.d.ts
@@ -1,21 +1,28 @@
import { Moment, MomentFormatSpecification, MomentInput } from 'moment'
import moment from 'moment'
import Vue from 'vue'

declare module '@nuxt/vue-app' {
interface Context {
$moment(input?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment
$moment: typeof moment
}
}

// Nuxt 2.9+
declare module '@nuxt/types' {
interface Context {
$moment(input?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment
$moment: typeof moment
}
}

declare module 'vue/types/vue' {
interface Vue {
$moment(input?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment
$moment: typeof moment
}
}

declare module 'vuex/types/index' {
interface Store<S> {
$moment: typeof moment
}
}