Skip to content

Commit

Permalink
feat: add experimentalSuppressUnknownPropErrors option
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 4, 2022
1 parent 2a78f39 commit ab5313a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Expand Up @@ -66,6 +66,10 @@
"type": "boolean",
"markdownDescription": "https://github.com/johnsoncodehk/volar/issues/1369"
},
"experimentalSuppressUnknownJsxPropertyErrors": {
"type": "boolean",
"markdownDescription": "Suppress unknown property errors in JSX and template. (Default true)"
},
"experimentalResolveStyleCssClasses": {
"enum": [
"scoped",
Expand Down
1 change: 1 addition & 0 deletions packages/vue-typescript/src/types.ts
Expand Up @@ -20,5 +20,6 @@ export interface VueCompilerOptions {
experimentalDisableTemplateSupport?: boolean;
experimentalResolveStyleCssClasses?: 'scoped' | 'always' | 'never';
experimentalAllowTypeNarrowingInInlineHandlers?: boolean;
experimentalSuppressUnknownJsxPropertyErrors?: boolean;
experimentalUseScriptLeadingCommentInTemplate?: boolean;
}
15 changes: 12 additions & 3 deletions packages/vue-typescript/src/typescriptRuntime.ts
Expand Up @@ -29,7 +29,7 @@ export function createTypeScriptRuntime(options: {
}) {

const { typescript: ts } = options;
const vueVersion = options.vueLsHost.getVueCompilationSettings().experimentalCompatMode ?? 3;
const vueCompilerOptions = options.vueLsHost.getVueCompilationSettings();
const tsFileVersions = new Map<string, string>();
const vueFiles = createVueFiles();
const plugins = [
Expand All @@ -38,7 +38,7 @@ export function createTypeScriptRuntime(options: {
];
const tsLsHost = createTsLsHost();
const tsLsRaw = ts.createLanguageService(tsLsHost);
const localTypesScript = ts.ScriptSnapshot.fromString(localTypes.getTypesCode(vueVersion));
const localTypesScript = ts.ScriptSnapshot.fromString(localTypes.getTypesCode(vueCompilerOptions.experimentalCompatMode ?? 3));

let lastProjectVersion: string | undefined;
let tsProjectVersion = 0;
Expand All @@ -58,7 +58,7 @@ export function createTypeScriptRuntime(options: {
},
getLocalTypesFiles: () => {
const fileNames = getLocalTypesFiles();
const code = localTypes.getTypesCode(vueVersion);
const code = localTypes.getTypesCode(vueCompilerOptions.experimentalCompatMode ?? 3);
return {
fileNames,
code,
Expand Down Expand Up @@ -279,6 +279,15 @@ export function createTypeScriptRuntime(options: {
}
let tsScript = options.vueLsHost.getScriptSnapshot(fileName);
if (tsScript) {
if ((vueCompilerOptions.experimentalSuppressUnknownJsxPropertyErrors ?? true) && basename === 'runtime-dom.d.ts') {
// allow arbitrary attributes
let tsScriptText = tsScript.getText(0, tsScript.getLength());
tsScriptText = tsScriptText.replace(
'type ReservedProps = {',
'type ReservedProps = { [name: string]: any',
);
tsScript = ts.ScriptSnapshot.fromString(tsScriptText);
}
scriptSnapshots.set(fileName.toLowerCase(), [version, tsScript]);
return tsScript;
}
Expand Down

0 comments on commit ab5313a

Please sign in to comment.