Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
chore: minor internal type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Mar 30, 2023
1 parent 3d85964 commit f578f28
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 21 deletions.
6 changes: 4 additions & 2 deletions example/components/Author.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
ref,
} from '@nuxtjs/composition-api'
/** @typedef {{ name: number }} User */
export default defineComponent({
props: {
userId: {
Expand All @@ -26,10 +28,10 @@ export default defineComponent({
},
},
setup(props) {
const user = ref({})
const user = ref(/** @type {User} */({}))
const { $http } = useContext()
useFetch(async () => {
user.value = await $http.$get(
`https://jsonplaceholder.typicode.com/users/${props.userId}`
Expand Down
6 changes: 4 additions & 2 deletions example/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fetch = require('node-fetch')
import fetch from 'node-fetch'
const serverlessEnvironment = !!process.env.NOW_BUILD

/** @type {import('@nuxt/types').NuxtConfig} */
export default {
server: {
port: process.env.PORT || 8000,
Expand All @@ -20,13 +21,14 @@ export default {
generate: {
interval: 2000,
async routes() {
/** @type {{ userId: number, id: number, title: string, body: string }[]} */
const posts = await fetch('https://jsonplaceholder.typicode.com/posts')
.then(res => res.json())
.then(d => d.slice(0, 20))
const routes = posts.map(post => `/posts/${post.id}`)

return ['/'].concat(routes)
},
exclude: ['/posts/23']
exclude: [RegExp('/posts/23')]
},
}
4 changes: 3 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"vue-content-placeholders": "^0.2.1"
},
"devDependencies": {
"nuxt": "latest"
"@nuxt/types": "^2.16.3",
"@types/node-fetch": "^2.6.3",
"nuxt": "^2.16.3"
},
"scripts": {
"dev": "nuxt",
Expand Down
12 changes: 7 additions & 5 deletions example/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ import {
ref,
} from '@nuxtjs/composition-api'
/** @typedef {{ userId: number, id: number, title: string, body: string }} Post */
export default defineComponent({
setup() {
const posts = ref(null)
const posts = ref(/** @type {Post[]} */([]))
const { $http } = useContext()
useFetch(async () => {
posts.value = await $http
.$get('https://jsonplaceholder.typicode.com/posts')
.then(posts => posts.slice(0, 20))
/** @type {Post[]} */
const data = await $http.$get('https://jsonplaceholder.typicode.com/posts')
posts.value = data.slice(0, 20)
})
return { posts }
Expand Down
2 changes: 1 addition & 1 deletion example/pages/posts/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineComponent({
post.value = await $http.$get(
`https://jsonplaceholder.typicode.com/posts/${params.value.id}`
)
})
})
return { post }
},
Expand Down
1 change: 1 addition & 0 deletions example/plugins/vue-placeholders.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue'
// @ts-ignore
import VueContentPlaceholders from 'vue-content-placeholders'

Vue.use(VueContentPlaceholders)
26 changes: 26 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
"strict": true,
"sourceMap": true,
"allowJs": true,
"checkJs": true,
"noEmit": true,
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "Node",
"lib": [
"ESNext",
"DOM"
],
"esModuleInterop": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"types": [
"node",
"@nuxt/http",
"@nuxt/types"
]
},
}
5 changes: 5 additions & 0 deletions example/types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"testcafe": "1.19.0",
"ts-loader": "^8.4.0",
"tsd": "^0.25.0",
"typescript": "4.9.4",
"typescript": "4.9.5",
"vitest": "^0.25.7",
"yorkie": "^2.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/api/posts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('@nuxt/types').ServerMiddleware} */
module.exports = (req, res) => {
res.setHeader('Content-Type', 'application/json')
return res.end(JSON.stringify({ id: req.url.split('/').slice(-1)[0] }))
res.end(JSON.stringify({ id: req.url?.split('/').slice(-1)[0] }))
}
4 changes: 4 additions & 0 deletions test/fixture/components/comp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<script>
import { defineComponent, ref, useFetch } from '@nuxtjs/composition-api'
/**
* @param {string} result
* @param {number} [time=100]
*/
export function fetcher(result, time = 100) {
return new Promise(resolve => {
return setTimeout(() => {
Expand Down
6 changes: 4 additions & 2 deletions test/fixture/pages/ttfb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export default defineComponent({
useFetch(() => {})
onMounted(() => {
dataset.ttfb =
globalThis.performance.getEntriesByType('navigation')[0].responseStart
const entry = globalThis.performance.getEntriesByType('navigation')[0]
if (entry instanceof PerformanceNavigationTiming) {
dataset.ttfb = entry.responseStart
}
})
return {
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @param {string} result
* @param {number} [time=100]
*/
export function fetcher(result, time = 100) {
return new Promise(resolve => {
return setTimeout(() => {
Expand Down
11 changes: 9 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"rootDir": ".",
"strict": true,
"sourceMap": true,
"allowJs": true,
"checkJs": true,
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "Node",
Expand All @@ -15,9 +17,14 @@
"@nuxtjs/composition-api/dist/runtime/globals": [
"./src/runtime/globals.ts"
],
"@nuxtjs/composition-api": ["./src/index.ts"]
"@nuxtjs/composition-api": ["./src/runtime/index.ts"]
},
"types": ["node", "@nuxt/types"]
},
"include": ["src/**/*.ts", "test/fixture/**/*.vue", "test/fixture/**/*.ts"]
"include": [
"src/**/*.ts",
"test/fixture/**/*.vue",
"test/fixture/**/*.js",
"test/fixture/**/*.ts"
]
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13465,10 +13465,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==

[email protected].4:
version "4.9.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==
[email protected].5:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@^3.3.3:
version "3.9.10"
Expand Down

0 comments on commit f578f28

Please sign in to comment.