Skip to content

Commit ab1ed6e

Browse files
committed
refactor: enable noUncheckedIndexedAccess in tsconfig
1 parent b96aa7c commit ab1ed6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+114
-114
lines changed

packages/component-meta/lib/base.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ interface ComponentMeta<T> {
468468
for (const symbol of exportedSymbols) {
469469
const [declaration] = symbol.getDeclarations() ?? [];
470470

471-
if (ts.isExportAssignment(declaration)) {
471+
if (declaration && ts.isExportAssignment(declaration)) {
472472
symbolNode = declaration.expression;
473473
}
474474
}
@@ -599,30 +599,30 @@ function createSchemaResolvers(
599599
let getSchema = () => [] as PropertyMetaSchema[];
600600

601601
if (call.parameters.length >= 2) {
602-
subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1], symbolNode);
603-
if ((call.parameters[1].valueDeclaration as any)?.dotDotDotToken) {
602+
subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1]!, symbolNode);
603+
if ((call.parameters[1]!.valueDeclaration as any)?.dotDotDotToken) {
604604
subtypeStr = getFullyQualifiedName(subtype);
605605
getSchema = () => typeChecker.getTypeArguments(subtype! as ts.TypeReference).map(resolveSchema);
606606
}
607607
else {
608608
subtypeStr = '[';
609609
for (let i = 1; i < call.parameters.length; i++) {
610-
subtypeStr += getFullyQualifiedName(typeChecker.getTypeOfSymbolAtLocation(call.parameters[i], symbolNode))
610+
subtypeStr += getFullyQualifiedName(typeChecker.getTypeOfSymbolAtLocation(call.parameters[i]!, symbolNode))
611611
+ ', ';
612612
}
613613
subtypeStr = subtypeStr.slice(0, -2) + ']';
614614
getSchema = () => {
615615
const result: PropertyMetaSchema[] = [];
616616
for (let i = 1; i < call.parameters.length; i++) {
617-
result.push(resolveSchema(typeChecker.getTypeOfSymbolAtLocation(call.parameters[i], symbolNode)));
617+
result.push(resolveSchema(typeChecker.getTypeOfSymbolAtLocation(call.parameters[i]!, symbolNode)));
618618
}
619619
return result;
620620
};
621621
}
622622
}
623623

624624
return {
625-
name: (typeChecker.getTypeOfSymbolAtLocation(call.parameters[0], symbolNode) as ts.StringLiteralType).value,
625+
name: (typeChecker.getTypeOfSymbolAtLocation(call.parameters[0]!, symbolNode) as ts.StringLiteralType).value,
626626
description: ts.displayPartsToString(call.getDocumentationComment(typeChecker)),
627627
tags: call.getJsDocTags().map(tag => ({
628628
name: tag.name,
@@ -646,10 +646,10 @@ function createSchemaResolvers(
646646
kind: 'event',
647647
type: typeChecker.signatureToString(signature),
648648
get schema() {
649-
return schema ??= signature.parameters.length > 0
649+
return schema ??= signature.parameters.length
650650
? typeChecker
651651
.getTypeArguments(
652-
typeChecker.getTypeOfSymbolAtLocation(signature.parameters[0], symbolNode) as ts.TypeReference,
652+
typeChecker.getTypeOfSymbolAtLocation(signature.parameters[0]!, symbolNode) as ts.TypeReference,
653653
)
654654
.map(resolveSchema)
655655
: undefined;
@@ -700,7 +700,7 @@ function createSchemaResolvers(
700700
};
701701
}
702702
else if (subtype.getCallSignatures().length === 1) {
703-
return resolveCallbackSchema(subtype.getCallSignatures()[0]);
703+
return resolveCallbackSchema(subtype.getCallSignatures()[0]!);
704704
}
705705

706706
return type;
@@ -909,7 +909,7 @@ function readTsComponentDefaultProps(
909909
// export default defineComponent({ ... })
910910
else if (ts.isCallExpression(component)) {
911911
if (component.arguments.length) {
912-
const arg = component.arguments[0];
912+
const arg = component.arguments[0]!;
913913
if (ts.isObjectLiteralExpression(arg)) {
914914
return arg;
915915
}

packages/language-core/lib/codegen/localTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type __VLS_TypePropsToOption<T> = {
123123
if (generated.has(name)) {
124124
continue;
125125
}
126-
const helper = helpers[name as keyof typeof helpers];
126+
const helper = helpers[name as keyof typeof helpers]!;
127127
yield helper.generate();
128128
generated.add(name);
129129
}

packages/language-core/lib/codegen/template/context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function createTemplateCodegenContext(
116116

117117
function resolveCodeFeatures(features: VueCodeInformation) {
118118
if (features.verification && stack.length) {
119-
const data = stack[stack.length - 1];
119+
const data = stack[stack.length - 1]!;
120120
if (data.ignoreError) {
121121
// We are currently in a region of code covered by a @vue-ignore directive, so don't
122122
// even bother performing any type-checking: set verification to false.
@@ -189,7 +189,7 @@ export function createTemplateCodegenContext(
189189

190190
return {
191191
get currentInfo() {
192-
return stack[stack.length - 1];
192+
return stack[stack.length - 1]!;
193193
},
194194
resolveCodeFeatures,
195195
inlineTsAsts: templateAst && templateInlineTsAsts.get(templateAst),
@@ -327,7 +327,7 @@ export function createTemplateCodegenContext(
327327
break;
328328
}
329329
case 'generic': {
330-
const text = content.trim();
330+
const text = content!.trim();
331331
if (text.startsWith('{') && text.endsWith('}')) {
332332
data.generic = {
333333
content: text.slice(1, -1),

packages/language-core/lib/codegen/template/element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function* generateComponent(
8888
];
8989
}
9090
else {
91-
const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
91+
const shouldCapitalize = matchImportName[0]!.toUpperCase() === matchImportName[0];
9292
yield* generateCamelized(
9393
shouldCapitalize ? capitalize(node.tag) : node.tag,
9494
'template',
@@ -160,7 +160,7 @@ export function* generateComponent(
160160
// navigation support
161161
yield `/** @type {[`;
162162
for (const tagOffset of tagOffsets) {
163-
for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
163+
for (const shouldCapitalize of (node.tag[0] === node.tag[0]!.toUpperCase() ? [false] : [true, false])) {
164164
yield `typeof __VLS_components.`;
165165
yield* generateCamelized(
166166
shouldCapitalize ? capitalize(node.tag) : node.tag,

packages/language-core/lib/codegen/template/elementDirectives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export function* generateModifiers(
131131
return;
132132
}
133133

134-
const startOffset = modifiers[0].loc.start.offset - 1;
134+
const startOffset = modifiers[0]!.loc.start.offset - 1;
135135
const endOffset = modifiers.at(-1)!.loc.end.offset;
136136

137137
yield* wrapWith(

packages/language-core/lib/codegen/template/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function* generateTemplateRefs(
166166
yield `(`;
167167
}
168168
for (let i = 0; i < refs.length; i++) {
169-
const { typeExp, offset } = refs[i];
169+
const { typeExp, offset } = refs[i]!;
170170
if (i) {
171171
yield ` | `;
172172
}
@@ -226,8 +226,7 @@ export function* forEachElementNode(
226226
}
227227
else if (node.type === CompilerDOM.NodeTypes.IF) {
228228
// v-if / v-else-if / v-else
229-
for (let i = 0; i < node.branches.length; i++) {
230-
const branch = node.branches[i];
229+
for (const branch of node.branches) {
231230
for (const childNode of branch.children) {
232231
yield* forEachElementNode(childNode);
233232
}

packages/language-core/lib/codegen/template/interpolation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function* forEachInterpolationSegment(
136136
if (ctxVars.length) {
137137
for (let i = 0; i < ctxVars.length; i++) {
138138
const lastVar = ctxVars[i - 1];
139-
const curVar = ctxVars[i];
139+
const curVar = ctxVars[i]!;
140140
const lastVarEnd = lastVar ? lastVar.offset + lastVar.text.length : 0;
141141

142142
if (curVar.isShorthand) {

packages/language-core/lib/codegen/template/templateChild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function* collectSingleRootNodes(
137137
return;
138138
}
139139

140-
const child = children[0];
140+
const child = children[0]!;
141141
if (child.type === CompilerDOM.NodeTypes.IF) {
142142
for (const branch of child.branches) {
143143
yield* collectSingleRootNodes(options, branch.children);

packages/language-core/lib/codegen/template/vIf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function* generateVIf(
1616
const originalBlockConditionsLength = ctx.blockConditions.length;
1717

1818
for (let i = 0; i < node.branches.length; i++) {
19-
const branch = node.branches[i];
19+
const branch = node.branches[i]!;
2020

2121
if (i === 0) {
2222
yield `if `;

packages/language-core/lib/codegen/template/vSlot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ function* generateSlotParameters(
114114
slotVar: string,
115115
): Generator<Code> {
116116
const { ts } = options;
117-
118117
const statement = ast.statements[0];
119-
if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
118+
119+
if (!statement || !ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
120120
return;
121121
}
122122

0 commit comments

Comments
 (0)