Skip to content
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

Added check for modifiersType existing in a mapped type #136

Closed
Closed
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
8 changes: 8 additions & 0 deletions util/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,21 @@ function isReadonlyPropertyIntersection(type: ts.Type, name: ts.__String, checke
});
}

function hasModifiersType(type: ts.Type): type is ts.Type & { modifiersType: ts.Type} {
return 'modifiersType' in type;
}

function isReadonlyPropertyFromMappedType(type: ts.Type, name: ts.__String, checker: ts.TypeChecker): boolean | undefined {
if (!isObjectType(type) || !isObjectFlagSet(type, ts.ObjectFlags.Mapped))
return;
const declaration = <ts.MappedTypeNode>type.symbol!.declarations![0];
// well-known symbols are not affected by mapped types
if (declaration.readonlyToken !== undefined && !/^__@[^@]+$/.test(<string>name))
return declaration.readonlyToken.kind !== ts.SyntaxKind.MinusToken;

if (!hasModifiersType(type))
return;

return isPropertyReadonlyInType((<{modifiersType: ts.Type}><unknown>type).modifiersType, name, checker);
}

Expand Down