Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-unnecessary-type-arguments] Use Symbol to check for the same type#4543

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export default util.createRule<[], MessageIds>({
create(context) {
const parserServices = util.getParserServices(context);
const checker = parserServices.program.getTypeChecker();
const sourceCode = context.getSourceCode();

function checkTSArgsAndParameters(
esParameters: TSESTree.TSTypeParameterInstantiation,
Expand All@@ -47,11 +46,20 @@ export default util.createRule<[], MessageIds>({
const i = esParameters.params.length - 1;
const arg = esParameters.params[i];
const param = typeParameters[i];

if (!param?.default) {
return;
}
// TODO: would like checker.areTypesEquivalent. https://github.com/Microsoft/TypeScript/issues/13502
if (
!param?.default ||
param.default.getText() !== sourceCode.getText(arg)
const defaultType = checker.getTypeAtLocation(param.default);
const argTsNode = parserServices.esTreeNodeToTSNodeMap.get(arg);
const argType = checker.getTypeAtLocation(argTsNode);
if (!argType.aliasSymbol && !defaultType.aliasSymbol) {
if (argType.flags !== defaultType.flags) {
return;
}
} else if (
argType.aliasSymbol !== defaultType.aliasSymbol ||
argType.aliasTypeArguments !== defaultType.aliasTypeArguments
) {
return;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -290,5 +290,32 @@ function bar<T = F<string>>() {}
bar();
`,
},
{
code: `
type DefaultE = { foo: string };
type T<E = DefaultE> = { box: E };
type G = T<DefaultE>;
declare module 'bar' {
type DefaultE = { somethingElse: true };
type G = T<DefaultE>;
}
`,
errors: [
{
line: 4,
column: 12,
messageId: 'unnecessaryTypeParameter',
},
],
output: `
type DefaultE = { foo: string };
type T<E = DefaultE> = { box: E };
type G = T;
declare module 'bar' {
type DefaultE = { somethingElse: true };
type G = T<DefaultE>;
}
`,
},
],
});

[8]ページ先頭

©2009-2025 Movatter.jp