Skip to content

Commit

Permalink
fix: move Record<string, unknown> to asFunctionalComponent to allow…
Browse files Browse the repository at this point in the history
… unknown props

close #2636
  • Loading branch information
johnsoncodehk committed Apr 21, 2023
1 parent 184cce1 commit fc093cf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
22 changes: 1 addition & 21 deletions packages/vue-language-core/src/languageModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export function createLanguageModules(
vueCompilerOptions: VueCompilerOptions,
): embedded.LanguageModule[] {

const patchSnapshots = new WeakMap<ts.IScriptSnapshot, ts.IScriptSnapshot>();

patchResolveModuleNames(ts, vueCompilerOptions);

const vueLanguagePlugin = getDefaultVueLanguagePlugins(
Expand Down Expand Up @@ -65,25 +63,7 @@ export function createLanguageModules(
if (basename === localTypes.typesFileName) {
return sharedTypesSnapshot;
}
let snapshot = host.getScriptSnapshot(fileName);
if (
snapshot
&& !vueCompilerOptions.strictTemplates
&& (
// vue 3
fileName.endsWith('/node_modules/@vue/runtime-core/dist/runtime-core.d.ts')
// vue 2.7
|| fileName.endsWith('/node_modules/vue/types/v3-component-proxy.d.ts')
)
) {
if (!patchSnapshots.has(snapshot)) {
let text = snapshot.getText(0, snapshot.getLength());
text = text.replace(/\$props: [^;]*/g, match => `$props: Record<string, unknown> & (${match.slice('$props: '.length)})`);
patchSnapshots.set(snapshot, ts.ScriptSnapshot.fromString(text));
}
snapshot = patchSnapshots.get(snapshot)!;
}
return snapshot;
return host.getScriptSnapshot(fileName);
},
};
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-language-core/src/utils/localTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type EmitEvent<F, E> =
export declare function asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends (...args: any) => any ? T
: K extends { $props?: infer Props, $slots?: infer Slots, $emit?: infer Emit }
? (props: Props, ctx?: { attrs?: any, expose?(exposed: K): void, slots?: Slots, emit?: Emit }) => JSX.Element & { __ctx?: typeof ctx, __props?: typeof props }
? (props: Props ${vueCompilerOptions.strictTemplates ? '' : '& Record<string, unknown>'}, ctx?: { attrs?: any, expose?(exposed: K): void, slots?: Slots, emit?: Emit }) => JSX.Element & { __ctx?: typeof ctx, __props?: typeof props }
: (_: T & Record<string, unknown>, ctx?: any) => { __ctx?: { attrs?: undefined, expose?: undefined, slots?: undefined, emit?: undefined }, __props?: T & Record<string, unknown> }; // IntrinsicElement
export declare function pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E): FillingEventArg<
PickNotAny<
Expand Down

0 comments on commit fc093cf

Please sign in to comment.