Skip to content

fix: add NoInfer to IntrinsicNodeParser #2133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/NodeParser/IntrinsicNodeParser.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export const intrinsicMethods: Record<string, ((v: string) => string) | undefine
Lowercase: (v) => v.toLowerCase(),
Capitalize: (v) => v[0].toUpperCase() + v.slice(1),
Uncapitalize: (v) => v[0].toLowerCase() + v.slice(1),
NoInfer: (v) => v,
};

export class IntrinsicNodeParser implements SubNodeParser {
2 changes: 2 additions & 0 deletions test/valid-data/string-literals-intrinsic/main.ts
Original file line number Diff line number Diff line change
@@ -4,11 +4,13 @@ type ResultUpper = Uppercase<Result>;
type ResultLower = Lowercase<ResultUpper>;
type ResultCapitalize = Capitalize<Result>;
type ResultUncapitalize = Uncapitalize<ResultCapitalize>;
type ResultNoInfer = NoInfer<Result>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this isn't how NoInfer is intended to be used and is a flaky test since all other intrinsic types are string-dependent and NoInfer might not be.

Please create a separate test with a code like:

// (I wrote this out of my head)

function test<T>(value: NoInfer<T>): T { return value } 
// create a function with type constraints as well (test<T extends something>())

export const MyObject = {
  str: test('asd'),
  // more samples with objects, type references, and so on...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but thanks for working in this <3


export interface MyObject {
result: Result;
resultUpper: ResultUpper;
resultLower: ResultLower;
resultCapitalize: ResultCapitalize;
resultUncapitalize: ResultUncapitalize;
resultNoInfer: ResultNoInfer;
}
12 changes: 11 additions & 1 deletion test/valid-data/string-literals-intrinsic/schema.json
Original file line number Diff line number Diff line change
@@ -49,14 +49,24 @@
"SUCCESS"
],
"type": "string"
},
"resultNoInfer": {
"enum": [
"ok",
"fail",
"ABORT",
"Success"
],
"type": "string"
}
},
"required": [
"result",
"resultUpper",
"resultLower",
"resultCapitalize",
"resultUncapitalize"
"resultUncapitalize",
"resultNoInfer"
],
"type": "object"
}

Unchanged files with check annotations Beta

}
const annotations = jsDocTags.reduce((result: Annotations, jsDocTag) => {
const value = this.parseJsDocTag(jsDocTag);

Check warning on line 79 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 79 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value
if (value !== undefined) {
if (BasicAnnotationsReader.requiresDollar.has(jsDocTag.name)) {
result["$" + jsDocTag.name] = value;

Check warning on line 82 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 82 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value
} else {
result[jsDocTag.name] = value;

Check warning on line 84 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 84 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value
}
}
return result;
if (isTextTag) {
return text;
}
let parsed = this.parseJson(text);

Check warning on line 102 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 102 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value
parsed = parsed === undefined ? text : parsed;

Check warning on line 103 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 103 in src/AnnotationsReader/BasicAnnotationsReader.ts

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value
if (BasicAnnotationsReader.jsonTags.has(jsDocTag.name)) {
return parsed;
} else if (this.extraTags?.has(jsDocTag.name)) {
return false;
}
const localSymbol: ts.Symbol = (node as any).localSymbol;

Check warning on line 41 in src/ExposeNodeParser.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 41 in src/ExposeNodeParser.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe member access .localSymbol on an `any` value

Check warning on line 41 in src/ExposeNodeParser.ts

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value

Check warning on line 41 in src/ExposeNodeParser.ts

GitHub Actions / Test (windows-latest)

Unsafe member access .localSymbol on an `any` value
return localSymbol ? "exportSymbol" in localSymbol : false;
}
const type = this.typeChecker.getTypeAtLocation(node);
// FIXME: remove special case
if (Array.isArray((type as any)?.typeArguments?.[0]?.types)) {

Check warning on line 24 in src/NodeParser/CallExpressionParser.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe member access .typeArguments on an `any` value

Check warning on line 24 in src/NodeParser/CallExpressionParser.ts

GitHub Actions / Test (windows-latest)

Unsafe member access .typeArguments on an `any` value
return new TupleType([
new UnionType((type as any).typeArguments[0].types.map((t: any) => new LiteralType(t.value))),

Check warning on line 26 in src/NodeParser/CallExpressionParser.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe argument of type `any` assigned to a parameter of type `readonly BaseType[]`

Check warning on line 26 in src/NodeParser/CallExpressionParser.ts

GitHub Actions / Test (ubuntu-latest)

Unsafe call of a(n) `any` typed value

Check warning on line 26 in src/NodeParser/CallExpressionParser.ts

GitHub Actions / Test (windows-latest)

Unsafe argument of type `any` assigned to a parameter of type `readonly BaseType[]`

Check warning on line 26 in src/NodeParser/CallExpressionParser.ts

GitHub Actions / Test (windows-latest)

Unsafe call of a(n) `any` typed value
]);
}