Skip to content

Conversation

@Andarist
Copy link
Contributor

fixes #57487

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 22, 2024

function hasOptionalModifiersProperty(mappedType: MappedType) {
const modifiersType = getApparentType(getModifiersTypeFromMappedType(mappedType));
if (!(modifiersType.flags & TypeFlags.Object)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: might also have to handle intersection (that's what isWeakType is doing) and I need to recheck behavior with unions

Choose a reason for hiding this comment

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

recheck behavior with union types later

Copy link
Member

Choose a reason for hiding this comment

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

@Mateusnasciment Please try to keep comments actionable and on-topic


type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what's the best strategy to avoid circularity here. I didn't look into it yet. I'm hitting the 🛌 but maybe somebody would chime in with some suggestions in the meantime ;p

const templateMapper = combineTypeMappers(objectType.mapper, mapper);
return instantiateType(getTemplateTypeFromMappedType(objectType.target as MappedType || objectType), templateMapper);
const type = instantiateType(getTemplateTypeFromMappedType(objectType.target as MappedType || objectType), templateMapper);
return addOptionality(type, /*isProperty*/ true, hasOptionalModifiersProperty(objectType));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: this should get the list of known optional properties and check if index is assignable to that, if the substitution happens using a known non-optional property then the optionality shouldn't be added

@ahejlsberg
Copy link
Member

I have what I think it the right fix in #57549. The main difference is that my PR is based on computing combined modifier flags, which I think is a better approach. It avoids resolving the members, which may cause circularities as you've observed. Also, member resolution is based on what members are known to be present, not which members might be present.

@Andarist Andarist closed this Feb 26, 2024
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Indexed Access of Partial Mapped Type with Union from Generic Function is missing undefined

5 participants