diff --git a/packages/server-renderer/package.json b/packages/server-renderer/package.json index a7534185aa6..fffcc771460 100644 --- a/packages/server-renderer/package.json +++ b/packages/server-renderer/package.json @@ -34,10 +34,11 @@ "source-map": "0.5.6" }, "devDependencies": { + "@types/webpack": "^4.41.32", + "file-loader": "^3.0.1", "memory-fs": "^0.5.0", "vue": "file:../..", - "webpack": "^4.46.0", - "file-loader": "^3.0.1" + "webpack": "^4.46.0" }, "homepage": "https://github.com/vuejs/vue/tree/dev/packages/vue-server-renderer#readme" } diff --git a/types/test/ssr-test.ts b/packages/server-renderer/types/test.ts similarity index 87% rename from types/test/ssr-test.ts rename to packages/server-renderer/types/test.ts index 37652b3324f..7a353066eda 100644 --- a/types/test/ssr-test.ts +++ b/packages/server-renderer/types/test.ts @@ -1,12 +1,9 @@ -import Vue, { VNode, VNodeDirective } from '../index' -import VueSSRClientPlugin = require('../../packages/vue-server-renderer/client-plugin') -import VueSSRServerPlugin = require('../../packages/vue-server-renderer/server-plugin') -import webpack = require('webpack') +import Vue, { VNode, VNodeDirective } from '../../../types/index' +import VueSSRClientPlugin from '../client-plugin' +import VueSSRServerPlugin from '../server-plugin' +import webpack from 'webpack' import { readFileSync } from 'fs' -import { - createRenderer, - createBundleRenderer -} from '../../packages/vue-server-renderer' +import { createRenderer, createBundleRenderer } from '.' function createApp(context: any) { return new Vue({ diff --git a/packages/server-renderer/types/tsconfig.json b/packages/server-renderer/types/tsconfig.json index 5e89be1ef9d..465615893cd 100644 --- a/packages/server-renderer/types/tsconfig.json +++ b/packages/server-renderer/types/tsconfig.json @@ -5,6 +5,7 @@ "moduleResolution": "node", "strict": true, "noEmit": true, + "allowSyntheticDefaultImports": true, "paths": { "vue": ["../../../types/index.d.ts"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe5925c21e5..470c95c6d4d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,6 +128,7 @@ importers: packages/server-renderer: specifiers: + '@types/webpack': ^4.41.32 chalk: ^4.0.0 file-loader: ^3.0.1 hash-sum: ^2.0.0 @@ -150,6 +151,7 @@ importers: serialize-javascript: 6.0.0 source-map: 0.5.6 devDependencies: + '@types/webpack': 4.41.32 file-loader: 3.0.1_webpack@4.46.0 memory-fs: 0.5.0 vue: 'file:' @@ -492,6 +494,39 @@ packages: '@types/node': 17.0.36 dev: true + /@types/source-list-map/0.1.2: + resolution: {integrity: sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==} + dev: true + + /@types/tapable/1.0.8: + resolution: {integrity: sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ==} + dev: true + + /@types/uglify-js/3.13.2: + resolution: {integrity: sha512-/xFrPIo+4zOeNGtVMbf9rUm0N+i4pDf1ynExomqtokIJmVzR3962lJ1UE+MmexMkA0cmN9oTzg5Xcbwge0Ij2Q==} + dependencies: + source-map: 0.6.1 + dev: true + + /@types/webpack-sources/3.2.0: + resolution: {integrity: sha512-Ft7YH3lEVRQ6ls8k4Ff1oB4jN6oy/XmU6tQISKdhfh+1mR+viZFphS6WL0IrtDOzvefmJg5a0s7ZQoRXwqTEFg==} + dependencies: + '@types/node': 17.0.36 + '@types/source-list-map': 0.1.2 + source-map: 0.7.3 + dev: true + + /@types/webpack/4.41.32: + resolution: {integrity: sha512-cb+0ioil/7oz5//7tZUSwbrSAN/NWHrQylz5cW8G0dWTcF/g+/dSdMlKVZspBYuMAN1+WnwHrkxiRrLcwd0Heg==} + dependencies: + '@types/node': 17.0.36 + '@types/tapable': 1.0.8 + '@types/uglify-js': 3.13.2 + '@types/webpack-sources': 3.2.0 + anymatch: 3.1.2 + source-map: 0.6.1 + dev: true + /@types/yauzl/2.10.0: resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==} requiresBuild: true @@ -4083,7 +4118,7 @@ packages: dev: true /normalize-path/2.1.1: - resolution: {integrity: sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=} + resolution: {integrity: sha512-3pKJwH184Xo/lnH6oyP1q2pMd7HcypqqmRs91/6/i2CGtWwIKGCkOOMTm/zXbgTEWHw1uNpNi/igc3ePOYHb6w==} engines: {node: '>=0.10.0'} dependencies: remove-trailing-separator: 1.1.0 @@ -5300,6 +5335,11 @@ packages: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} + /source-map/0.7.3: + resolution: {integrity: sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==} + engines: {node: '>= 8'} + dev: true + /sourcemap-codec/1.4.8: resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} dev: true @@ -6375,7 +6415,7 @@ packages: 'file:': resolution: {directory: '', type: directory} name: vue - version: 2.6.14 + version: 2.7.0-alpha.3 dependencies: '@vue/compiler-sfc': link:packages/compiler-sfc dev: true diff --git a/types/index.d.ts b/types/index.d.ts index b724d798e98..2e2bfdd052c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -11,8 +11,8 @@ export { ComponentOptions, FunctionalComponentOptions, RenderContext, - // PropType, - // PropOptions, + PropType, + PropOptions, ComputedOptions, WatchHandler, WatchOptions, @@ -52,8 +52,8 @@ export { ComponentRenderProxy } from './v3-component-proxy' export { - PropType, - PropOptions, + // PropType, + // PropOptions, ExtractPropTypes, ExtractDefaultPropTypes } from './v3-component-props' diff --git a/types/options.d.ts b/types/options.d.ts index 8868e7cf87c..80ab87ad0fa 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -250,10 +250,22 @@ export interface RenderContext { injections: any } -import { PropOptions, PropType } from './v3-component-props' +export type Prop = + | { (): T } + | { new (...args: never[]): T & object } + | { new (...args: string[]): Function } + +export type PropType = Prop | Prop[] export type PropValidator = PropOptions | PropType +export interface PropOptions { + type?: PropType + required?: boolean + default?: T | null | undefined | (() => T | null | undefined) + validator?(value: unknown): boolean +} + export type RecordPropsDefinition = { [K in keyof T]: PropValidator } diff --git a/types/test/v3/setup-test.ts b/types/test/v3/setup-test.ts index 8ad8eefe40c..15572f736e9 100644 --- a/types/test/v3/setup-test.ts +++ b/types/test/v3/setup-test.ts @@ -1,4 +1,4 @@ -import Vue, { defineComponent } from '../../index' +import Vue, { defineComponent, PropType } from '../../index' // object props Vue.extend({ @@ -78,3 +78,18 @@ defineComponent({ } } }) + +defineComponent({ + props: { + foo: null as any as PropType<{ a: number }> + }, + data() { + this.foo?.a + }, + setup(props) { + const res = props.foo?.a.toFixed(2) + // @ts-expect-error + res.charAt(1) + res?.charAt(1) + } +}) diff --git a/types/v3-component-props.d.ts b/types/v3-component-props.d.ts index 7abf0d4b8da..f4d0a787023 100644 --- a/types/v3-component-props.d.ts +++ b/types/v3-component-props.d.ts @@ -22,8 +22,8 @@ export interface PropOptions { export type PropType = PropConstructor | PropConstructor[] type PropConstructor = - | { new (...args: any[]): T & object } | { (): T } + | { new (...args: never[]): T & object } | { new (...args: string[]): Function } type RequiredKeys = {