Merge branch 'master' into interfaceFixes

This commit is contained in:
Arthur Ozga 2016-12-11 21:51:29 -08:00
commit 1ba6c8605b
26 changed files with 2111 additions and 841 deletions

View file

@ -3503,20 +3503,7 @@ namespace ts {
}
if (!popTypeResolution()) {
if ((<VariableLikeDeclaration>symbol.valueDeclaration).type) {
// Variable has type annotation that circularly references the variable itself
type = unknownType;
error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation,
symbolToString(symbol));
}
else {
// Variable has initializer that circularly references the variable itself
type = anyType;
if (compilerOptions.noImplicitAny) {
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
symbolToString(symbol));
}
}
type = reportCircularityError(symbol);
}
links.type = type;
}
@ -3650,11 +3637,33 @@ namespace ts {
function getTypeOfInstantiatedSymbol(symbol: Symbol): Type {
const links = getSymbolLinks(symbol);
if (!links.type) {
links.type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
}
let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
if (!popTypeResolution()) {
type = reportCircularityError(symbol);
}
links.type = type;
}
return links.type;
}
function reportCircularityError(symbol: Symbol) {
// Check if variable has type annotation that circularly references the variable itself
if ((<VariableLikeDeclaration>symbol.valueDeclaration).type) {
error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation,
symbolToString(symbol));
return unknownType;
}
// Otherwise variable has initializer that circularly references the variable itself
if (compilerOptions.noImplicitAny) {
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
symbolToString(symbol));
}
return anyType;
}
function getTypeOfSymbol(symbol: Symbol): Type {
if (symbol.flags & SymbolFlags.Instantiated) {
return getTypeOfInstantiatedSymbol(symbol);
@ -4548,12 +4557,11 @@ namespace ts {
// Resolve upfront such that recursive references see an empty object type.
setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined);
// In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type,
// and T as the template type. If K is of the form 'keyof S', the mapped type and S are
// homomorphic and we copy property modifiers from corresponding properties in S.
// and T as the template type.
const typeParameter = getTypeParameterFromMappedType(type);
const constraintType = getConstraintTypeFromMappedType(type);
const homomorphicType = getHomomorphicTypeFromMappedType(type);
const templateType = getTemplateTypeFromMappedType(type);
const modifiersType = getModifiersTypeFromMappedType(type);
const templateReadonly = !!type.declaration.readonlyToken;
const templateOptional = !!type.declaration.questionToken;
// First, if the constraint type is a type parameter, obtain the base constraint. Then,
@ -4572,11 +4580,11 @@ namespace ts {
// Otherwise, for type string create a string index signature.
if (t.flags & TypeFlags.StringLiteral) {
const propName = (<LiteralType>t).text;
const homomorphicProp = homomorphicType && getPropertyOfType(homomorphicType, propName);
const isOptional = templateOptional || !!(homomorphicProp && homomorphicProp.flags & SymbolFlags.Optional);
const modifiersProp = getPropertyOfType(modifiersType, propName);
const isOptional = templateOptional || !!(modifiersProp && modifiersProp.flags & SymbolFlags.Optional);
const prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | (isOptional ? SymbolFlags.Optional : 0), propName);
prop.type = propType;
prop.isReadonly = templateReadonly || homomorphicProp && isReadonlySymbol(homomorphicProp);
prop.isReadonly = templateReadonly || modifiersProp && isReadonlySymbol(modifiersProp);
members[propName] = prop;
}
else if (t.flags & TypeFlags.String) {
@ -4603,9 +4611,16 @@ namespace ts {
unknownType);
}
function getHomomorphicTypeFromMappedType(type: MappedType) {
const constraint = getConstraintDeclaration(getTypeParameterFromMappedType(type));
return constraint.kind === SyntaxKind.TypeOperator ? instantiateType(getTypeFromTypeNode((<TypeOperatorNode>constraint).type), type.mapper || identityMapper) : undefined;
function getModifiersTypeFromMappedType(type: MappedType) {
if (!type.modifiersType) {
// If the mapped type was declared as { [P in keyof T]: X } or as { [P in K]: X }, where
// K is constrained to 'K extends keyof T', then we will copy property modifiers from T.
const declaredType = <MappedType>getTypeFromMappedTypeNode(type.declaration);
const constraint = getConstraintTypeFromMappedType(declaredType);
const extendedConstraint = constraint.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>constraint) : constraint;
type.modifiersType = extendedConstraint.flags & TypeFlags.Index ? instantiateType((<IndexType>extendedConstraint).type, type.mapper || identityMapper) : emptyObjectType;
}
return type.modifiersType;
}
function getErasedTemplateTypeFromMappedType(type: MappedType) {
@ -4703,33 +4718,24 @@ namespace ts {
* The apparent type of a type parameter is the base constraint instantiated with the type parameter
* as the type argument for the 'this' type.
*/
function getApparentTypeOfTypeParameter(type: TypeParameter) {
function getApparentTypeOfTypeVariable(type: TypeVariable) {
if (!type.resolvedApparentType) {
let constraintType = getConstraintOfTypeParameter(type);
let constraintType = getConstraintOfTypeVariable(type);
while (constraintType && constraintType.flags & TypeFlags.TypeParameter) {
constraintType = getConstraintOfTypeParameter(<TypeParameter>constraintType);
constraintType = getConstraintOfTypeVariable(<TypeVariable>constraintType);
}
type.resolvedApparentType = getTypeWithThisArgument(constraintType || emptyObjectType, type);
}
return type.resolvedApparentType;
}
/**
* The apparent type of an indexed access T[K] is the type of T's string index signature, if any.
*/
function getApparentTypeOfIndexedAccess(type: IndexedAccessType) {
return getIndexTypeOfType(getApparentType(type.objectType), IndexKind.String) || type;
}
/**
* For a type parameter, return the base constraint of the type parameter. For the string, number,
* boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
* type itself. Note that the apparent type of a union type is the union type itself.
*/
function getApparentType(type: Type): Type {
const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(<TypeParameter>type) :
type.flags & TypeFlags.IndexedAccess ? getApparentTypeOfIndexedAccess(<IndexedAccessType>type) :
type;
const t = type.flags & TypeFlags.TypeVariable ? getApparentTypeOfTypeVariable(<TypeVariable>type) : type;
return t.flags & TypeFlags.StringLike ? globalStringType :
t.flags & TypeFlags.NumberLike ? globalNumberType :
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
@ -5315,6 +5321,12 @@ namespace ts {
return typeParameter.constraint === noConstraintType ? undefined : typeParameter.constraint;
}
function getConstraintOfTypeVariable(type: TypeVariable): Type {
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) :
type.flags & TypeFlags.IndexedAccess ? (<IndexedAccessType>type).constraint :
undefined;
}
function getParentSymbolOfTypeParameter(typeParameter: TypeParameter): Symbol {
return getSymbolOfNode(getDeclarationOfKind(typeParameter.symbol, SyntaxKind.TypeParameter).parent);
}
@ -5990,6 +6002,24 @@ namespace ts {
const type = <IndexedAccessType>createType(TypeFlags.IndexedAccess);
type.objectType = objectType;
type.indexType = indexType;
// We eagerly compute the constraint of the indexed access type such that circularity
// errors are immediately caught and reported. For example, class C { x: this["x"] }
// becomes an error only when the constraint is eagerly computed.
if (type.objectType.flags & TypeFlags.StructuredType) {
// The constraint of T[K], where T is an object, union, or intersection type,
// is the type of the string index signature of T, if any.
type.constraint = getIndexTypeOfType(type.objectType, IndexKind.String);
}
else if (type.objectType.flags & TypeFlags.TypeVariable) {
// The constraint of T[K], where T is a type variable, is A[K], where A is the
// apparent type of T.
const apparentType = getApparentTypeOfTypeVariable(<TypeVariable>type.objectType);
if (apparentType !== emptyObjectType) {
type.constraint = isTypeOfKind((<IndexedAccessType>type).indexType, TypeFlags.StringLike) ?
getIndexedAccessType(apparentType, (<IndexedAccessType>type).indexType) :
getIndexTypeOfType(apparentType, IndexKind.String);
}
}
return type;
}
@ -6068,14 +6098,19 @@ namespace ts {
}
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
if (maybeTypeOfKind(indexType, TypeFlags.TypeVariable | TypeFlags.Index) || isGenericMappedType(objectType)) {
// If the index type is generic, if the object type is generic and doesn't originate in an expression,
// or if the object type is a mapped type with a generic constraint, we are performing a higher-order
// index access where we cannot meaningfully access the properties of the object type. Note that for a
// generic T and a non-generic K, we eagerly resolve T[K] if it originates in an expression. This is to
// preserve backwards compatibility. For example, an element access 'this["foo"]' has always been resolved
// eagerly using the constraint type of 'this' at the given location.
if (maybeTypeOfKind(indexType, TypeFlags.TypeVariable | TypeFlags.Index) ||
maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && !(accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression) ||
isGenericMappedType(objectType)) {
if (objectType.flags & TypeFlags.Any) {
return objectType;
}
// If the index type is generic or if the object type is a mapped type with a generic constraint,
// we are performing a higher-order index access where we cannot meaningfully access the properties
// of the object type. In those cases, we first check that the index type is assignable to 'keyof T'
// for the object type.
// We first check that the index type is assignable to 'keyof T' for the object type.
if (accessNode) {
if (!isTypeAssignableTo(indexType, getIndexType(objectType))) {
error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType));
@ -6092,6 +6127,7 @@ namespace ts {
const id = objectType.id + "," + indexType.id;
return indexedAccessTypes[id] || (indexedAccessTypes[id] = createIndexedAccessType(objectType, indexType));
}
// In the following we resolve T[K] to the type of the property in T selected by K.
const apparentObjectType = getApparentType(objectType);
if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) {
const propTypes: Type[] = [];
@ -7281,8 +7317,7 @@ namespace ts {
return result;
}
}
if (target.flags & TypeFlags.TypeParameter) {
else if (target.flags & TypeFlags.TypeParameter) {
// A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P].
if (getObjectFlags(source) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(<MappedType>source) === getIndexType(target)) {
if (!(<MappedType>source).declaration.questionToken) {
@ -7311,10 +7346,10 @@ namespace ts {
return result;
}
}
// Given a type parameter T with a constraint C, a type S is assignable to
// Given a type variable T with a constraint C, a type S is assignable to
// keyof T if S is assignable to keyof C.
if ((<IndexType>target).type.flags & TypeFlags.TypeParameter) {
const constraint = getConstraintOfTypeParameter(<TypeParameter>(<IndexType>target).type);
if ((<IndexType>target).type.flags & TypeFlags.TypeVariable) {
const constraint = getConstraintOfTypeVariable(<TypeVariable>(<IndexType>target).type);
if (constraint) {
if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
return result;
@ -7330,6 +7365,14 @@ namespace ts {
return result;
}
}
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
// A is the apparent type of S.
if ((<IndexedAccessType>target).constraint) {
if (result = isRelatedTo(source, (<IndexedAccessType>target).constraint, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
}
if (source.flags & TypeFlags.TypeParameter) {
@ -7338,6 +7381,7 @@ namespace ts {
const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
const templateType = getTemplateTypeFromMappedType(<MappedType>target);
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
@ -7359,6 +7403,16 @@ namespace ts {
}
}
}
else if (source.flags & TypeFlags.IndexedAccess) {
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
// A is the apparent type of S.
if ((<IndexedAccessType>source).constraint) {
if (result = isRelatedTo((<IndexedAccessType>source).constraint, target, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
}
else {
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to same target type, see if relationship holds for all type arguments
@ -15028,8 +15082,8 @@ namespace ts {
function isLiteralContextualType(contextualType: Type) {
if (contextualType) {
if (contextualType.flags & TypeFlags.TypeParameter) {
const apparentType = getApparentTypeOfTypeParameter(<TypeParameter>contextualType);
if (contextualType.flags & TypeFlags.TypeVariable) {
const apparentType = getApparentTypeOfTypeVariable(<TypeVariable>contextualType);
// If the type parameter is constrained to the base primitive type we're checking for,
// consider this a literal context. For example, given a type parameter 'T extends string',
// this causes us to infer string literal types for T.
@ -15864,7 +15918,7 @@ namespace ts {
checkSourceElement(node.type);
const type = <MappedType>getTypeFromMappedTypeNode(node);
const constraintType = getConstraintTypeFromMappedType(type);
const keyType = constraintType.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(<TypeParameter>constraintType) : constraintType;
const keyType = constraintType.flags & TypeFlags.TypeVariable ? getApparentTypeOfTypeVariable(<TypeVariable>constraintType) : constraintType;
checkTypeAssignableTo(keyType, stringType, node.typeParameter.constraint);
}

View file

@ -841,7 +841,7 @@ namespace ts {
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = []): ParsedCommandLine {
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], extraFileExtensions: FileExtensionInfo[] = []): ParsedCommandLine {
const errors: Diagnostic[] = [];
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
const resolvedPath = toPath(configFileName || "", basePath, getCanonicalFileName);
@ -981,7 +981,7 @@ namespace ts {
includeSpecs = ["**/*"];
}
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors);
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors, extraFileExtensions);
if (result.fileNames.length === 0 && !hasProperty(json, "files") && resolutionStack.length === 0) {
errors.push(
@ -1185,7 +1185,7 @@ namespace ts {
* @param host The host used to resolve files and directories.
* @param errors An array for diagnostic reporting.
*/
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[]): ExpandResult {
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], extraFileExtensions: FileExtensionInfo[]): ExpandResult {
basePath = normalizePath(basePath);
// The exclude spec list is converted into a regular expression, which allows us to quickly
@ -1219,7 +1219,7 @@ namespace ts {
// Rather than requery this for each file and filespec, we query the supported extensions
// once and store it on the expansion context.
const supportedExtensions = getSupportedExtensions(options);
const supportedExtensions = getSupportedExtensions(options, extraFileExtensions);
// Literal files are always included verbatim. An "include" or "exclude" specification cannot
// remove a literal file.

View file

@ -1924,8 +1924,18 @@ namespace ts {
export const supportedJavascriptExtensions = [".js", ".jsx"];
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
export function getSupportedExtensions(options?: CompilerOptions): string[] {
return options && options.allowJs ? allSupportedExtensions : supportedTypeScriptExtensions;
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: FileExtensionInfo[]): string[] {
const needAllExtensions = options && options.allowJs;
if (!extraFileExtensions || extraFileExtensions.length === 0) {
return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
}
const extensions = (needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions).slice(0);
for (const extInfo of extraFileExtensions) {
if (needAllExtensions || extInfo.scriptKind === ScriptKind.TS) {
extensions.push(extInfo.extension);
}
}
return extensions;
}
export function hasJavaScriptFileExtension(fileName: string) {
@ -1936,10 +1946,10 @@ namespace ts {
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
}
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) {
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, extraFileExtensions?: FileExtensionInfo[]) {
if (!fileName) { return false; }
for (const extension of getSupportedExtensions(compilerOptions)) {
for (const extension of getSupportedExtensions(compilerOptions, extraFileExtensions)) {
if (fileExtensionIs(fileName, extension)) {
return true;
}

View file

@ -2944,6 +2944,7 @@ namespace ts {
typeParameter?: TypeParameter;
constraintType?: Type;
templateType?: Type;
modifiersType?: Type;
mapper?: TypeMapper; // Instantiation mapper
}
@ -2979,6 +2980,8 @@ namespace ts {
}
export interface TypeVariable extends Type {
/* @internal */
resolvedApparentType: Type;
/* @internal */
resolvedIndexType: IndexType;
}
@ -2991,8 +2994,6 @@ namespace ts {
/* @internal */
mapper?: TypeMapper; // Instantiation mapper
/* @internal */
resolvedApparentType: Type;
/* @internal */
isThisType?: boolean;
}
@ -3001,6 +3002,7 @@ namespace ts {
export interface IndexedAccessType extends TypeVariable {
objectType: Type;
indexType: Type;
constraint?: Type;
}
// keyof T types (TypeFlags.Index)
@ -3097,6 +3099,12 @@ namespace ts {
ThisProperty
}
export interface FileExtensionInfo {
extension: string;
scriptKind: ScriptKind;
isMixedContent: boolean;
}
export interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;

View file

@ -16,7 +16,6 @@ namespace ts.textStorage {
it("text based storage should be have exactly the same as script version cache", () => {
debugger
const host = ts.projectSystem.createServerHost([f]);
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));

View file

@ -140,7 +140,6 @@ namespace ts.projectSystem {
export interface TestServerHostCreationParameters {
useCaseSensitiveFileNames?: boolean;
executingFilePath?: string;
libFile?: FileOrFolder;
currentDirectory?: string;
}
@ -1145,6 +1144,69 @@ namespace ts.projectSystem {
checkNumberOfProjects(projectService, {});
});
it("reload regular file after closing", () => {
const f1 = {
path: "/a/b/app.ts",
content: "x."
};
const f2 = {
path: "/a/b/lib.ts",
content: "let x: number;"
};
const host = createServerHost([f1, f2, libFile]);
const service = createProjectService(host);
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: toExternalFiles([f1.path, f2.path]), options: {} })
service.openClientFile(f1.path);
service.openClientFile(f2.path, "let x: string");
service.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
// should contain completions for string
assert.isTrue(completions1.entries.some(e => e.name === "charAt"), "should contain 'charAt'");
assert.isFalse(completions1.entries.some(e => e.name === "toExponential"), "should not contain 'toExponential'");
service.closeClientFile(f2.path);
const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
// should contain completions for string
assert.isFalse(completions2.entries.some(e => e.name === "charAt"), "should not contain 'charAt'");
assert.isTrue(completions2.entries.some(e => e.name === "toExponential"), "should contain 'toExponential'");
});
it("clear mixed content file after closing", () => {
const f1 = {
path: "/a/b/app.ts",
content: " "
};
const f2 = {
path: "/a/b/lib.html",
content: "<html/>"
};
const host = createServerHost([f1, f2, libFile]);
const service = createProjectService(host);
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: [{ fileName: f1.path }, { fileName: f2.path, hasMixedContent: true }], options: {} })
service.openClientFile(f1.path);
service.openClientFile(f2.path, "let somelongname: string");
service.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
assert.isTrue(completions1.entries.some(e => e.name === "somelongname"), "should contain 'somelongname'");
service.closeClientFile(f2.path);
const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
assert.isFalse(completions2.entries.some(e => e.name === "somelongname"), "should not contain 'somelongname'");
const sf2 = service.externalProjects[0].getLanguageService().getProgram().getSourceFile(f2.path);
assert.equal(sf2.text, "");
});
it("external project with included config file opened after configured project", () => {
const file1 = {
path: "/a/b/f1.ts",
@ -1529,6 +1591,67 @@ namespace ts.projectSystem {
checkProjectActualFiles(projectService.inferredProjects[1], [file2.path]);
});
it("tsconfig script block support", () => {
const file1 = {
path: "/a/b/f1.ts",
content: ` `
};
const file2 = {
path: "/a/b/f2.html",
content: `var hello = "hello";`
};
const config = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({ compilerOptions: { allowJs: true } })
};
const host = createServerHost([file1, file2, config]);
const session = createSession(host);
openFilesForSession([file1], session);
const projectService = session.getProjectService();
// HTML file will not be included in any projects yet
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [file1.path]);
// Specify .html extension as mixed content
const extraFileExtensions = [{ extension: ".html", scriptKind: ScriptKind.JS, isMixedContent: true }];
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { extraFileExtensions });
session.executeCommand(configureHostRequest).response;
// HTML file still not included in the project as it is closed
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [file1.path]);
// Open HTML file
projectService.applyChangesInOpenFiles(
/*openFiles*/[{ fileName: file2.path, hasMixedContent: true, scriptKind: ScriptKind.JS, content: `var hello = "hello";` }],
/*changedFiles*/undefined,
/*closedFiles*/undefined);
// Now HTML file is included in the project
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [file1.path, file2.path]);
// Check identifiers defined in HTML content are available in .ts file
const project = projectService.configuredProjects[0];
let completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 1);
assert(completions && completions.entries[0].name === "hello", `expected entry hello to be in completion list`);
// Close HTML file
projectService.applyChangesInOpenFiles(
/*openFiles*/undefined,
/*changedFiles*/undefined,
/*closedFiles*/[file2.path]);
// HTML file is still included in project
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [file1.path, file2.path]);
// Check identifiers defined in HTML content are not available in .ts file
completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 5);
assert(completions && completions.entries[0].name !== "hello", `unexpected hello entry in completion list`);
});
it("project structure update is deferred if files are not added\removed", () => {
const file1 = {
path: "/a/b/f1.ts",

View file

@ -108,6 +108,7 @@ namespace ts.server {
export interface HostConfiguration {
formatCodeOptions: FormatCodeSettings;
hostInfo: string;
extraFileExtensions?: FileExtensionInfo[];
}
interface ConfigFileConversionResult {
@ -132,13 +133,16 @@ namespace ts.server {
interface FilePropertyReader<T> {
getFileName(f: T): string;
getScriptKind(f: T): ScriptKind;
hasMixedContent(f: T): boolean;
hasMixedContent(f: T, extraFileExtensions: FileExtensionInfo[]): boolean;
}
const fileNamePropertyReader: FilePropertyReader<string> = {
getFileName: x => x,
getScriptKind: _ => undefined,
hasMixedContent: _ => false
hasMixedContent: (fileName, extraFileExtensions) => {
const mixedContentExtensions = ts.map(ts.filter(extraFileExtensions, item => item.isMixedContent), item => item.extension);
return forEach(mixedContentExtensions, extension => fileExtensionIs(fileName, extension))
}
};
const externalFilePropertyReader: FilePropertyReader<protocol.ExternalFile> = {
@ -282,7 +286,8 @@ namespace ts.server {
this.hostConfiguration = {
formatCodeOptions: getDefaultFormatCodeSettings(this.host),
hostInfo: "Unknown host"
hostInfo: "Unknown host",
extraFileExtensions: []
};
this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames, host.getCurrentDirectory());
@ -486,7 +491,7 @@ namespace ts.server {
// If a change was made inside "folder/file", node will trigger the callback twice:
// one with the fileName being "folder/file", and the other one with "folder".
// We don't respond to the second one.
if (fileName && !ts.isSupportedSourceFileName(fileName, project.getCompilerOptions())) {
if (fileName && !ts.isSupportedSourceFileName(fileName, project.getCompilerOptions(), this.hostConfiguration.extraFileExtensions)) {
return;
}
@ -642,6 +647,9 @@ namespace ts.server {
let projectsToRemove: Project[];
for (const p of info.containingProjects) {
if (p.projectKind === ProjectKind.Configured) {
if (info.hasMixedContent) {
info.registerFileUpdate();
}
// last open file in configured project - close it
if ((<ConfiguredProject>p).deleteOpenRef() === 0) {
(projectsToRemove || (projectsToRemove = [])).push(p);
@ -810,7 +818,9 @@ namespace ts.server {
this.host,
getDirectoryPath(configFilename),
/*existingOptions*/ {},
configFilename);
configFilename,
/*resolutionStack*/ [],
this.hostConfiguration.extraFileExtensions);
if (parsedCommandLine.errors.length) {
errors = concatenate(errors, parsedCommandLine.errors);
@ -914,7 +924,7 @@ namespace ts.server {
for (const f of files) {
const rootFilename = propertyReader.getFileName(f);
const scriptKind = propertyReader.getScriptKind(f);
const hasMixedContent = propertyReader.hasMixedContent(f);
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.extraFileExtensions);
if (this.host.fileExists(rootFilename)) {
const info = this.getOrCreateScriptInfoForNormalizedPath(toNormalizedPath(rootFilename), /*openedByClient*/ clientFileName == rootFilename, /*fileContent*/ undefined, scriptKind, hasMixedContent);
project.addRoot(info);
@ -960,7 +970,7 @@ namespace ts.server {
rootFilesChanged = true;
if (!scriptInfo) {
const scriptKind = propertyReader.getScriptKind(f);
const hasMixedContent = propertyReader.hasMixedContent(f);
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.extraFileExtensions);
scriptInfo = this.getOrCreateScriptInfoForNormalizedPath(normalizedPath, /*openedByClient*/ false, /*fileContent*/ undefined, scriptKind, hasMixedContent);
}
}
@ -1110,6 +1120,9 @@ namespace ts.server {
if (info) {
if (openedByClient && !info.isScriptOpen()) {
info.open(fileContent);
if (hasMixedContent) {
info.registerFileUpdate();
}
}
else if (fileContent !== undefined) {
info.reload(fileContent);
@ -1144,6 +1157,10 @@ namespace ts.server {
mergeMaps(this.hostConfiguration.formatCodeOptions, convertFormatOptions(args.formatOptions));
this.logger.info("Format host information updated");
}
if (args.extraFileExtensions) {
this.hostConfiguration.extraFileExtensions = args.extraFileExtensions;
this.logger.info("Host file extension mappings updated");
}
}
}

View file

@ -1,4 +1,4 @@
/// <reference path="..\services\services.ts" />
/// <reference path="..\services\services.ts" />
/// <reference path="utilities.ts"/>
/// <reference path="scriptInfo.ts"/>
/// <reference path="lsHost.ts"/>
@ -187,6 +187,10 @@ namespace ts.server {
public languageServiceEnabled = true;
builder: Builder;
/**
* Set of files names that were updated since the last call to getChangesSinceVersion.
*/
private updatedFileNames: Map<string>;
/**
* Set of files that was returned from the last call to getChangesSinceVersion.
*/
@ -480,6 +484,10 @@ namespace ts.server {
this.markAsDirty();
}
registerFileUpdate(fileName: string) {
(this.updatedFileNames || (this.updatedFileNames = createMap<string>()))[fileName] = fileName;
}
markAsDirty() {
this.projectStateVersion++;
}
@ -667,10 +675,12 @@ namespace ts.server {
isInferred: this.projectKind === ProjectKind.Inferred,
options: this.getCompilerOptions()
};
const updatedFileNames = this.updatedFileNames;
this.updatedFileNames = undefined;
// check if requested version is the same that we have reported last time
if (this.lastReportedFileNames && lastKnownVersion === this.lastReportedVersion) {
// if current structure version is the same - return info witout any changes
if (this.projectStructureVersion == this.lastReportedVersion) {
// if current structure version is the same - return info without any changes
if (this.projectStructureVersion == this.lastReportedVersion && !updatedFileNames) {
return { info, projectErrors: this.projectErrors };
}
// compute and return the difference
@ -679,6 +689,7 @@ namespace ts.server {
const added: string[] = [];
const removed: string[] = [];
const updated: string[] = getOwnKeys(updatedFileNames);
for (const id in currentFiles) {
if (!hasProperty(lastReportedFileNames, id)) {
added.push(id);
@ -691,7 +702,7 @@ namespace ts.server {
}
this.lastReportedFileNames = currentFiles;
this.lastReportedVersion = this.projectStructureVersion;
return { info, changes: { added, removed }, projectErrors: this.projectErrors };
return { info, changes: { added, removed, updated }, projectErrors: this.projectErrors };
}
else {
// unknown version - return everything

View file

@ -1,4 +1,4 @@
/**
/**
* Declaration module describing the TypeScript Server protocol
*/
namespace ts.server.protocol {
@ -918,6 +918,10 @@ namespace ts.server.protocol {
* List of removed files
*/
removed: string[];
/**
* List of updated files
*/
updated: string[];
}
/**
@ -990,6 +994,11 @@ namespace ts.server.protocol {
* The format options to use during formatting and other code editing features.
*/
formatOptions?: FormatCodeSettings;
/**
* The host's additional supported file extensions
*/
extraFileExtensions?: FileExtensionInfo[];
}
/**

View file

@ -28,9 +28,9 @@ namespace ts.server {
this.switchToScriptVersionCache(newText);
}
public useText() {
public useText(newText?: string) {
this.svc = undefined;
this.reloadFromFile();
this.setText(newText);
}
public edit(start: number, end: number, newText: string) {
@ -170,7 +170,6 @@ namespace ts.server {
private isOpen: boolean;
// TODO: allow to update hasMixedContent from the outside
constructor(
private readonly host: ServerHost,
readonly fileName: NormalizedPath,
@ -199,7 +198,8 @@ namespace ts.server {
public close() {
this.isOpen = false;
this.textStorage.useText();
this.textStorage.useText(this.hasMixedContent ? "" : undefined);
this.markContainingProjectsAsDirty();
}
public getSnapshot() {
@ -267,6 +267,12 @@ namespace ts.server {
return this.containingProjects[0];
}
registerFileUpdate(): void {
for (const p of this.containingProjects) {
p.registerFileUpdate(this.path);
}
}
setFormatOptions(formatSettings: FormatCodeSettings): void {
if (formatSettings) {
if (!this.formatCodeSettings) {

View file

@ -1,4 +1,4 @@
/// <reference path="types.d.ts" />
/// <reference path="types.d.ts" />
/// <reference path="shared.ts" />
namespace ts.server {

View file

@ -0,0 +1,57 @@
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(3,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(7,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(15,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(19,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(23,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(27,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(28,5): error TS2502: 'y' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(29,5): error TS2502: 'z' is referenced directly or indirectly in its own type annotation.
==== tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts (8 errors) ====
type T1 = {
x: T1["x"]; // Error
~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
};
type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
~~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
y: number;
}
declare let x2: T2<"x">;
let x2x = x2.x;
interface T3<T extends T3<T>> {
x: T["x"]; // Error
~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}
interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
~~~~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}
class C1 {
x: C1["x"]; // Error
~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}
class C2 {
x: this["y"]; // Error
~~~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
y: this["z"]; // Error
~~~~~~~~~~~~~
!!! error TS2502: 'y' is referenced directly or indirectly in its own type annotation.
z: this["x"]; // Error
~~~~~~~~~~~~~
!!! error TS2502: 'z' is referenced directly or indirectly in its own type annotation.
}

View file

@ -0,0 +1,70 @@
//// [circularIndexedAccessErrors.ts]
type T1 = {
x: T1["x"]; // Error
};
type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
y: number;
}
declare let x2: T2<"x">;
let x2x = x2.x;
interface T3<T extends T3<T>> {
x: T["x"]; // Error
}
interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
}
class C1 {
x: C1["x"]; // Error
}
class C2 {
x: this["y"]; // Error
y: this["z"]; // Error
z: this["x"]; // Error
}
//// [circularIndexedAccessErrors.js]
var x2x = x2.x;
var C1 = (function () {
function C1() {
}
return C1;
}());
var C2 = (function () {
function C2() {
}
return C2;
}());
//// [circularIndexedAccessErrors.d.ts]
declare type T1 = {
x: T1["x"];
};
declare type T2<K extends "x" | "y"> = {
x: T2<K>[K];
y: number;
};
declare let x2: T2<"x">;
declare let x2x: any;
interface T3<T extends T3<T>> {
x: T["x"];
}
interface T4<T extends T4<T>> {
x: T4<T>["x"];
}
declare class C1 {
x: C1["x"];
}
declare class C2 {
x: this["y"];
y: this["z"];
z: this["x"];
}

View file

@ -249,6 +249,53 @@ function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[
let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
}
function f80<T extends { a: { x: any } }>(obj: T) {
let a1 = obj.a; // { x: any }
let a2 = obj['a']; // { x: any }
let a3 = obj['a'] as T['a']; // T["a"]
let x1 = obj.a.x; // any
let x2 = obj['a']['x']; // any
let x3 = obj['a']['x'] as T['a']['x']; // T["a"]["x"]
}
function f81<T extends { a: { x: any } }>(obj: T) {
return obj['a']['x'] as T['a']['x'];
}
function f82() {
let x1 = f81({ a: { x: "hello" } }); // string
let x2 = f81({ a: { x: 42 } }); // number
}
function f83<T extends { [x: string]: { x: any } }, K extends keyof T>(obj: T, key: K) {
return obj[key]['x'] as T[K]['x'];
}
function f84() {
let x1 = f83({ foo: { x: "hello" } }, "foo"); // string
let x2 = f83({ bar: { x: 42 } }, "bar"); // number
}
class C1 {
x: number;
get<K extends keyof this>(key: K) {
return this[key];
}
set<K extends keyof this>(key: K, value: this[K]) {
this[key] = value;
}
foo() {
let x1 = this.x; // number
let x2 = this["x"]; // number
let x3 = this.get("x"); // this["x"]
let x4 = getProperty(this, "x"); // this["x"]
this.x = 42;
this["x"] = 42;
this.set("x", 42);
setProperty(this, "x", 42);
}
}
// Repros from #12011
class Base {
@ -364,7 +411,25 @@ interface R {
function f<K extends keyof R>(p: K) {
let a: any;
a[p].add; // any
}
}
// Repro from #12651
type MethodDescriptor = {
name: string;
args: any[];
returnValue: any;
}
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
type SomeMethodDescriptor = {
name: "someMethod";
args: [string, number];
returnValue: string[];
}
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
//// [keyofAndIndexedAccess.js]
var __extends = (this && this.__extends) || function (d, b) {
@ -536,6 +601,49 @@ function f74(func) {
var a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number
var b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
}
function f80(obj) {
var a1 = obj.a; // { x: any }
var a2 = obj['a']; // { x: any }
var a3 = obj['a']; // T["a"]
var x1 = obj.a.x; // any
var x2 = obj['a']['x']; // any
var x3 = obj['a']['x']; // T["a"]["x"]
}
function f81(obj) {
return obj['a']['x'];
}
function f82() {
var x1 = f81({ a: { x: "hello" } }); // string
var x2 = f81({ a: { x: 42 } }); // number
}
function f83(obj, key) {
return obj[key]['x'];
}
function f84() {
var x1 = f83({ foo: { x: "hello" } }, "foo"); // string
var x2 = f83({ bar: { x: 42 } }, "bar"); // number
}
var C1 = (function () {
function C1() {
}
C1.prototype.get = function (key) {
return this[key];
};
C1.prototype.set = function (key, value) {
this[key] = value;
};
C1.prototype.foo = function () {
var x1 = this.x; // number
var x2 = this["x"]; // number
var x3 = this.get("x"); // this["x"]
var x4 = getProperty(this, "x"); // this["x"]
this.x = 42;
this["x"] = 42;
this.set("x", 42);
setProperty(this, "x", 42);
};
return C1;
}());
// Repros from #12011
var Base = (function () {
function Base() {
@ -604,6 +712,7 @@ function f(p) {
var a;
a[p].add; // any
}
var result = dispatchMethod("someMethod", ["hello", 35]);
//// [keyofAndIndexedAccess.d.ts]
@ -716,6 +825,29 @@ declare function f71(func: <T, U>(x: T, y: U) => Partial<T & U>): void;
declare function f72(func: <T, U, K extends keyof T | keyof U>(x: T, y: U, k: K) => (T & U)[K]): void;
declare function f73(func: <T, U, K extends keyof (T & U)>(x: T, y: U, k: K) => (T & U)[K]): void;
declare function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[K]): void;
declare function f80<T extends {
a: {
x: any;
};
}>(obj: T): void;
declare function f81<T extends {
a: {
x: any;
};
}>(obj: T): T["a"]["x"];
declare function f82(): void;
declare function f83<T extends {
[x: string]: {
x: any;
};
}, K extends keyof T>(obj: T, key: K): T[K]["x"];
declare function f84(): void;
declare class C1 {
x: number;
get<K extends keyof this>(key: K): this[K];
set<K extends keyof this>(key: K, value: this[K]): void;
foo(): void;
}
declare class Base {
get<K extends keyof this>(prop: K): this[K];
set<K extends keyof this>(prop: K, value: this[K]): void;
@ -723,12 +855,12 @@ declare class Base {
declare class Person extends Base {
parts: number;
constructor(parts: number);
getParts(): number;
getParts(): this["parts"];
}
declare class OtherPerson {
parts: number;
constructor(parts: number);
getParts(): number;
getParts(): this["parts"];
}
declare function path<T, K1 extends keyof T>(obj: T, key1: K1): T[K1];
declare function path<T, K1 extends keyof T, K2 extends keyof T[K1]>(obj: T, key1: K1, key2: K2): T[K1][K2];
@ -776,3 +908,15 @@ interface R {
p: number;
}
declare function f<K extends keyof R>(p: K): void;
declare type MethodDescriptor = {
name: string;
args: any[];
returnValue: any;
};
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
declare type SomeMethodDescriptor = {
name: "someMethod";
args: [string, number];
returnValue: string[];
};
declare let result: string[];

View file

@ -951,396 +951,628 @@ function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[
>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 247, 46))
}
function f80<T extends { a: { x: any } }>(obj: T) {
>f80 : Symbol(f80, Decl(keyofAndIndexedAccess.ts, 248, 1))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 250, 13))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 250, 29))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 250, 13))
let a1 = obj.a; // { x: any }
>a1 : Symbol(a1, Decl(keyofAndIndexedAccess.ts, 251, 7))
>obj.a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
let a2 = obj['a']; // { x: any }
>a2 : Symbol(a2, Decl(keyofAndIndexedAccess.ts, 252, 7))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>'a' : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
let a3 = obj['a'] as T['a']; // T["a"]
>a3 : Symbol(a3, Decl(keyofAndIndexedAccess.ts, 253, 7))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>'a' : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 250, 13))
let x1 = obj.a.x; // any
>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 254, 7))
>obj.a.x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 250, 29))
>obj.a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 250, 29))
let x2 = obj['a']['x']; // any
>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 255, 7))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>'a' : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>'x' : Symbol(x, Decl(keyofAndIndexedAccess.ts, 250, 29))
let x3 = obj['a']['x'] as T['a']['x']; // T["a"]["x"]
>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 256, 7))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 250, 42))
>'a' : Symbol(a, Decl(keyofAndIndexedAccess.ts, 250, 24))
>'x' : Symbol(x, Decl(keyofAndIndexedAccess.ts, 250, 29))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 250, 13))
}
function f81<T extends { a: { x: any } }>(obj: T) {
>f81 : Symbol(f81, Decl(keyofAndIndexedAccess.ts, 257, 1))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 259, 13))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 259, 24))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 259, 29))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 259, 42))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 259, 13))
return obj['a']['x'] as T['a']['x'];
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 259, 42))
>'a' : Symbol(a, Decl(keyofAndIndexedAccess.ts, 259, 24))
>'x' : Symbol(x, Decl(keyofAndIndexedAccess.ts, 259, 29))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 259, 13))
}
function f82() {
>f82 : Symbol(f82, Decl(keyofAndIndexedAccess.ts, 261, 1))
let x1 = f81({ a: { x: "hello" } }); // string
>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 264, 7))
>f81 : Symbol(f81, Decl(keyofAndIndexedAccess.ts, 257, 1))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 264, 18))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 264, 23))
let x2 = f81({ a: { x: 42 } }); // number
>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 265, 7))
>f81 : Symbol(f81, Decl(keyofAndIndexedAccess.ts, 257, 1))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 265, 18))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 265, 23))
}
function f83<T extends { [x: string]: { x: any } }, K extends keyof T>(obj: T, key: K) {
>f83 : Symbol(f83, Decl(keyofAndIndexedAccess.ts, 266, 1))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 268, 13))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 268, 26))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 268, 39))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 268, 51))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 268, 13))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 268, 71))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 268, 13))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 268, 78))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 268, 51))
return obj[key]['x'] as T[K]['x'];
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 268, 71))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 268, 78))
>'x' : Symbol(x, Decl(keyofAndIndexedAccess.ts, 268, 39))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 268, 13))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 268, 51))
}
function f84() {
>f84 : Symbol(f84, Decl(keyofAndIndexedAccess.ts, 270, 1))
let x1 = f83({ foo: { x: "hello" } }, "foo"); // string
>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 273, 7))
>f83 : Symbol(f83, Decl(keyofAndIndexedAccess.ts, 266, 1))
>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 273, 18))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 273, 25))
let x2 = f83({ bar: { x: 42 } }, "bar"); // number
>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 274, 7))
>f83 : Symbol(f83, Decl(keyofAndIndexedAccess.ts, 266, 1))
>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 274, 18))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 274, 25))
}
class C1 {
>C1 : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
x: number;
>x : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
get<K extends keyof this>(key: K) {
>get : Symbol(C1.get, Decl(keyofAndIndexedAccess.ts, 278, 14))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 279, 8))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 279, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 279, 8))
return this[key];
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 279, 30))
}
set<K extends keyof this>(key: K, value: this[K]) {
>set : Symbol(C1.set, Decl(keyofAndIndexedAccess.ts, 281, 5))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 282, 8))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 282, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 282, 8))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 282, 37))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 282, 8))
this[key] = value;
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 282, 30))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 282, 37))
}
foo() {
>foo : Symbol(C1.foo, Decl(keyofAndIndexedAccess.ts, 284, 5))
let x1 = this.x; // number
>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 286, 11))
>this.x : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>x : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
let x2 = this["x"]; // number
>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 287, 11))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>"x" : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
let x3 = this.get("x"); // this["x"]
>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 288, 11))
>this.get : Symbol(C1.get, Decl(keyofAndIndexedAccess.ts, 278, 14))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>get : Symbol(C1.get, Decl(keyofAndIndexedAccess.ts, 278, 14))
let x4 = getProperty(this, "x"); // this["x"]
>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 289, 11))
>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
this.x = 42;
>this.x : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>x : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
this["x"] = 42;
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>"x" : Symbol(C1.x, Decl(keyofAndIndexedAccess.ts, 277, 10))
this.set("x", 42);
>this.set : Symbol(C1.set, Decl(keyofAndIndexedAccess.ts, 281, 5))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
>set : Symbol(C1.set, Decl(keyofAndIndexedAccess.ts, 281, 5))
setProperty(this, "x", 42);
>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1))
>this : Symbol(C1, Decl(keyofAndIndexedAccess.ts, 275, 1))
}
}
// Repros from #12011
class Base {
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1))
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1))
get<K extends keyof this>(prop: K) {
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 252, 12))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 253, 8))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 253, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 253, 8))
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 299, 12))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 300, 8))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 300, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 300, 8))
return this[prop];
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 253, 30))
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 300, 30))
}
set<K extends keyof this>(prop: K, value: this[K]) {
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 255, 5))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 256, 8))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 256, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 256, 8))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 256, 38))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 256, 8))
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 302, 5))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 303, 8))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 303, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 303, 8))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 303, 38))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 303, 8))
this[prop] = value;
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 256, 30))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 256, 38))
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1))
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 303, 30))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 303, 38))
}
}
class Person extends Base {
>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 259, 1))
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1))
>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 306, 1))
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1))
parts: number;
>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 261, 27))
>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 308, 27))
constructor(parts: number) {
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 263, 16))
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 310, 16))
super();
>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1))
>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1))
this.set("parts", parts);
>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 255, 5))
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 259, 1))
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 255, 5))
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 263, 16))
>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 302, 5))
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 306, 1))
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 302, 5))
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 310, 16))
}
getParts() {
>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 266, 5))
>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 313, 5))
return this.get("parts")
>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 252, 12))
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 259, 1))
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 252, 12))
>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 299, 12))
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 306, 1))
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 299, 12))
}
}
class OtherPerson {
>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 270, 1))
>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 317, 1))
parts: number;
>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 272, 19))
>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 319, 19))
constructor(parts: number) {
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 274, 16))
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 321, 16))
setProperty(this, "parts", parts);
>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1))
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 270, 1))
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 274, 16))
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 317, 1))
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 321, 16))
}
getParts() {
>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 276, 5))
>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 323, 5))
return getProperty(this, "parts")
>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26))
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 270, 1))
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 317, 1))
}
}
// Modified repro from #12544
function path<T, K1 extends keyof T>(obj: T, key1: K1): T[K1];
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 284, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 284, 37))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 284, 44))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 284, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 284, 16))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 331, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 331, 37))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 331, 44))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 331, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 331, 16))
function path<T, K1 extends keyof T, K2 extends keyof T[K1]>(obj: T, key1: K1, key2: K2): T[K1][K2];
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 285, 36))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 285, 61))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 285, 68))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 285, 78))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 285, 36))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 285, 36))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 332, 36))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 332, 61))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 332, 68))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 332, 78))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 332, 36))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 332, 36))
function path<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(obj: T, key1: K1, key2: K2, key3: K3): T[K1][K2][K3];
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16))
>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 286, 60))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 286, 89))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 286, 96))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 286, 106))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36))
>key3 : Symbol(key3, Decl(keyofAndIndexedAccess.ts, 286, 116))
>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 286, 60))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36))
>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 286, 60))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16))
>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 333, 60))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 333, 89))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 333, 96))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 333, 106))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36))
>key3 : Symbol(key3, Decl(keyofAndIndexedAccess.ts, 333, 116))
>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 333, 60))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36))
>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 333, 60))
function path(obj: any, ...keys: (string | number)[]): any;
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 287, 14))
>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 287, 23))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 334, 14))
>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 334, 23))
function path(obj: any, ...keys: (string | number)[]): any {
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 288, 14))
>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 288, 23))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 335, 14))
>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 335, 23))
let result = obj;
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 288, 14))
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7))
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 335, 14))
for (let k of keys) {
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 290, 12))
>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 288, 23))
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 337, 12))
>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 335, 23))
result = result[k];
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7))
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7))
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 290, 12))
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7))
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7))
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 337, 12))
}
return result;
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7))
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7))
}
type Thing = {
>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 294, 1))
>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 341, 1))
a: { x: number, y: string },
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 296, 14))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 297, 8))
>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 297, 19))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 343, 14))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 344, 8))
>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 344, 19))
b: boolean
>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 297, 32))
>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 344, 32))
};
function f1(thing: Thing) {
>f1 : Symbol(f1, Decl(keyofAndIndexedAccess.ts, 299, 2))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12))
>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 294, 1))
>f1 : Symbol(f1, Decl(keyofAndIndexedAccess.ts, 346, 2))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12))
>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 341, 1))
let x1 = path(thing, 'a'); // { x: number, y: string }
>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 303, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12))
>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 350, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12))
let x2 = path(thing, 'a', 'y'); // string
>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 304, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12))
>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 351, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12))
let x3 = path(thing, 'b'); // boolean
>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 305, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12))
>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 352, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12))
let x4 = path(thing, ...['a', 'x']); // any
>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 306, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12))
>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 353, 7))
>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59))
>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12))
}
// Repro from comment in #12114
const assignTo2 = <T, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, key1: K1, key2: K2) =>
>assignTo2 : Symbol(assignTo2, Decl(keyofAndIndexedAccess.ts, 311, 5))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 311, 41))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21))
>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 311, 66))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 311, 76))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 311, 86))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 311, 41))
>assignTo2 : Symbol(assignTo2, Decl(keyofAndIndexedAccess.ts, 358, 5))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 358, 41))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21))
>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 358, 66))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 358, 76))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 358, 86))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 358, 41))
(value: T[K1][K2]) => object[key1][key2] = value;
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 312, 5))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 311, 41))
>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 311, 66))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 311, 76))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 311, 86))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 312, 5))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 359, 5))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19))
>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21))
>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 358, 41))
>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 358, 66))
>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 358, 76))
>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 358, 86))
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 359, 5))
// Modified repro from #12573
declare function one<T>(handler: (t: T) => void): T
>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 312, 53))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 316, 21))
>handler : Symbol(handler, Decl(keyofAndIndexedAccess.ts, 316, 24))
>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 316, 34))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 316, 21))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 316, 21))
>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 359, 53))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 363, 21))
>handler : Symbol(handler, Decl(keyofAndIndexedAccess.ts, 363, 24))
>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 363, 34))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 363, 21))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 363, 21))
var empty = one(() => {}) // inferred as {}, expected
>empty : Symbol(empty, Decl(keyofAndIndexedAccess.ts, 317, 3))
>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 312, 53))
>empty : Symbol(empty, Decl(keyofAndIndexedAccess.ts, 364, 3))
>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 359, 53))
type Handlers<T> = { [K in keyof T]: (t: T[K]) => void }
>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 317, 25))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 319, 14))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 319, 22))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 319, 14))
>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 319, 38))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 319, 14))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 319, 22))
>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 364, 25))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 366, 14))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 366, 22))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 366, 14))
>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 366, 38))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 366, 14))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 366, 22))
declare function on<T>(handlerHash: Handlers<T>): T
>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 319, 56))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 320, 20))
>handlerHash : Symbol(handlerHash, Decl(keyofAndIndexedAccess.ts, 320, 23))
>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 317, 25))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 320, 20))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 320, 20))
>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 366, 56))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 367, 20))
>handlerHash : Symbol(handlerHash, Decl(keyofAndIndexedAccess.ts, 367, 23))
>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 364, 25))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 367, 20))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 367, 20))
var hashOfEmpty1 = on({ test: () => {} }); // {}
>hashOfEmpty1 : Symbol(hashOfEmpty1, Decl(keyofAndIndexedAccess.ts, 321, 3))
>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 319, 56))
>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 321, 23))
>hashOfEmpty1 : Symbol(hashOfEmpty1, Decl(keyofAndIndexedAccess.ts, 368, 3))
>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 366, 56))
>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 368, 23))
var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean }
>hashOfEmpty2 : Symbol(hashOfEmpty2, Decl(keyofAndIndexedAccess.ts, 322, 3))
>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 319, 56))
>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 322, 23))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 322, 31))
>hashOfEmpty2 : Symbol(hashOfEmpty2, Decl(keyofAndIndexedAccess.ts, 369, 3))
>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 366, 56))
>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 369, 23))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 369, 31))
// Repro from #12624
interface Options1<Data, Computed> {
>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 322, 52))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 326, 19))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 326, 24))
>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 369, 52))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 373, 19))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 373, 24))
data?: Data
>data : Symbol(Options1.data, Decl(keyofAndIndexedAccess.ts, 326, 36))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 326, 19))
>data : Symbol(Options1.data, Decl(keyofAndIndexedAccess.ts, 373, 36))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 373, 19))
computed?: Computed;
>computed : Symbol(Options1.computed, Decl(keyofAndIndexedAccess.ts, 327, 15))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 326, 24))
>computed : Symbol(Options1.computed, Decl(keyofAndIndexedAccess.ts, 374, 15))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 373, 24))
}
declare class Component1<Data, Computed> {
>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 329, 1))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30))
>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 376, 1))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30))
constructor(options: Options1<Data, Computed>);
>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 332, 16))
>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 322, 52))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30))
>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 379, 16))
>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 369, 52))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30))
get<K extends keyof (Data & Computed)>(key: K): (Data & Computed)[K];
>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 332, 51))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 333, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 333, 43))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 333, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 333, 8))
>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 379, 51))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 380, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 380, 43))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 380, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 380, 8))
}
let c1 = new Component1({
>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 336, 3))
>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 329, 1))
>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 383, 3))
>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 376, 1))
data: {
>data : Symbol(data, Decl(keyofAndIndexedAccess.ts, 336, 25))
>data : Symbol(data, Decl(keyofAndIndexedAccess.ts, 383, 25))
hello: ""
>hello : Symbol(hello, Decl(keyofAndIndexedAccess.ts, 337, 11))
>hello : Symbol(hello, Decl(keyofAndIndexedAccess.ts, 384, 11))
}
});
c1.get("hello");
>c1.get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 332, 51))
>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 336, 3))
>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 332, 51))
>c1.get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 379, 51))
>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 383, 3))
>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 379, 51))
// Repro from #12625
interface Options2<Data, Computed> {
>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 342, 16))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 346, 19))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 346, 24))
>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 389, 16))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 393, 19))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 393, 24))
data?: Data
>data : Symbol(Options2.data, Decl(keyofAndIndexedAccess.ts, 346, 36))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 346, 19))
>data : Symbol(Options2.data, Decl(keyofAndIndexedAccess.ts, 393, 36))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 393, 19))
computed?: Computed;
>computed : Symbol(Options2.computed, Decl(keyofAndIndexedAccess.ts, 347, 15))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 346, 24))
>computed : Symbol(Options2.computed, Decl(keyofAndIndexedAccess.ts, 394, 15))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 393, 24))
}
declare class Component2<Data, Computed> {
>Component2 : Symbol(Component2, Decl(keyofAndIndexedAccess.ts, 349, 1))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30))
>Component2 : Symbol(Component2, Decl(keyofAndIndexedAccess.ts, 396, 1))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30))
constructor(options: Options2<Data, Computed>);
>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 352, 16))
>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 342, 16))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30))
>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 399, 16))
>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 389, 16))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30))
get<K extends keyof Data | keyof Computed>(key: K): (Data & Computed)[K];
>get : Symbol(Component2.get, Decl(keyofAndIndexedAccess.ts, 352, 51))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 353, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 353, 47))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 353, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 353, 8))
>get : Symbol(Component2.get, Decl(keyofAndIndexedAccess.ts, 399, 51))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 400, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30))
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 400, 47))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 400, 8))
>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25))
>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 400, 8))
}
// Repro from #12641
interface R {
>R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 354, 1))
>R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 401, 1))
p: number;
>p : Symbol(R.p, Decl(keyofAndIndexedAccess.ts, 358, 13))
>p : Symbol(R.p, Decl(keyofAndIndexedAccess.ts, 405, 13))
}
function f<K extends keyof R>(p: K) {
>f : Symbol(f, Decl(keyofAndIndexedAccess.ts, 360, 1))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 362, 11))
>R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 354, 1))
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 362, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 362, 11))
>f : Symbol(f, Decl(keyofAndIndexedAccess.ts, 407, 1))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 409, 11))
>R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 401, 1))
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 409, 30))
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 409, 11))
let a: any;
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 363, 7))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 410, 7))
a[p].add; // any
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 363, 7))
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 362, 30))
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 410, 7))
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 409, 30))
}
// Repro from #12651
type MethodDescriptor = {
>MethodDescriptor : Symbol(MethodDescriptor, Decl(keyofAndIndexedAccess.ts, 412, 1))
name: string;
>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 416, 25))
args: any[];
>args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 417, 14))
returnValue: any;
>returnValue : Symbol(returnValue, Decl(keyofAndIndexedAccess.ts, 418, 13))
}
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
>dispatchMethod : Symbol(dispatchMethod, Decl(keyofAndIndexedAccess.ts, 420, 1))
>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32))
>MethodDescriptor : Symbol(MethodDescriptor, Decl(keyofAndIndexedAccess.ts, 412, 1))
>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 422, 60))
>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32))
>args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 422, 76))
>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32))
>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32))
type SomeMethodDescriptor = {
>SomeMethodDescriptor : Symbol(SomeMethodDescriptor, Decl(keyofAndIndexedAccess.ts, 422, 112))
name: "someMethod";
>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 424, 29))
args: [string, number];
>args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 425, 20))
returnValue: string[];
>returnValue : Symbol(returnValue, Decl(keyofAndIndexedAccess.ts, 426, 24))
}
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 430, 3))
>dispatchMethod : Symbol(dispatchMethod, Decl(keyofAndIndexedAccess.ts, 420, 1))
>SomeMethodDescriptor : Symbol(SomeMethodDescriptor, Decl(keyofAndIndexedAccess.ts, 422, 112))

View file

@ -626,8 +626,8 @@ function f33<S extends Shape, K extends keyof S>(shape: S, key: K) {
>K : K
let name = getProperty(shape, "name");
>name : string
>getProperty(shape, "name") : string
>name : S["name"]
>getProperty(shape, "name") : S["name"]
>getProperty : <T, K extends keyof T>(obj: T, key: K) => T[K]
>shape : S
>"name" : "name"
@ -1146,6 +1146,245 @@ function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[
>'b' : "b"
}
function f80<T extends { a: { x: any } }>(obj: T) {
>f80 : <T extends { a: { x: any; }; }>(obj: T) => void
>T : T
>a : { x: any; }
>x : any
>obj : T
>T : T
let a1 = obj.a; // { x: any }
>a1 : { x: any; }
>obj.a : { x: any; }
>obj : T
>a : { x: any; }
let a2 = obj['a']; // { x: any }
>a2 : { x: any; }
>obj['a'] : { x: any; }
>obj : T
>'a' : "a"
let a3 = obj['a'] as T['a']; // T["a"]
>a3 : T["a"]
>obj['a'] as T['a'] : T["a"]
>obj['a'] : { x: any; }
>obj : T
>'a' : "a"
>T : T
let x1 = obj.a.x; // any
>x1 : any
>obj.a.x : any
>obj.a : { x: any; }
>obj : T
>a : { x: any; }
>x : any
let x2 = obj['a']['x']; // any
>x2 : any
>obj['a']['x'] : any
>obj['a'] : { x: any; }
>obj : T
>'a' : "a"
>'x' : "x"
let x3 = obj['a']['x'] as T['a']['x']; // T["a"]["x"]
>x3 : T["a"]["x"]
>obj['a']['x'] as T['a']['x'] : T["a"]["x"]
>obj['a']['x'] : any
>obj['a'] : { x: any; }
>obj : T
>'a' : "a"
>'x' : "x"
>T : T
}
function f81<T extends { a: { x: any } }>(obj: T) {
>f81 : <T extends { a: { x: any; }; }>(obj: T) => T["a"]["x"]
>T : T
>a : { x: any; }
>x : any
>obj : T
>T : T
return obj['a']['x'] as T['a']['x'];
>obj['a']['x'] as T['a']['x'] : T["a"]["x"]
>obj['a']['x'] : any
>obj['a'] : { x: any; }
>obj : T
>'a' : "a"
>'x' : "x"
>T : T
}
function f82() {
>f82 : () => void
let x1 = f81({ a: { x: "hello" } }); // string
>x1 : string
>f81({ a: { x: "hello" } }) : string
>f81 : <T extends { a: { x: any; }; }>(obj: T) => T["a"]["x"]
>{ a: { x: "hello" } } : { a: { x: string; }; }
>a : { x: string; }
>{ x: "hello" } : { x: string; }
>x : string
>"hello" : "hello"
let x2 = f81({ a: { x: 42 } }); // number
>x2 : number
>f81({ a: { x: 42 } }) : number
>f81 : <T extends { a: { x: any; }; }>(obj: T) => T["a"]["x"]
>{ a: { x: 42 } } : { a: { x: number; }; }
>a : { x: number; }
>{ x: 42 } : { x: number; }
>x : number
>42 : 42
}
function f83<T extends { [x: string]: { x: any } }, K extends keyof T>(obj: T, key: K) {
>f83 : <T extends { [x: string]: { x: any; }; }, K extends keyof T>(obj: T, key: K) => T[K]["x"]
>T : T
>x : string
>x : any
>K : K
>T : T
>obj : T
>T : T
>key : K
>K : K
return obj[key]['x'] as T[K]['x'];
>obj[key]['x'] as T[K]['x'] : T[K]["x"]
>obj[key]['x'] : any
>obj[key] : T[K]
>obj : T
>key : K
>'x' : "x"
>T : T
>K : K
}
function f84() {
>f84 : () => void
let x1 = f83({ foo: { x: "hello" } }, "foo"); // string
>x1 : string
>f83({ foo: { x: "hello" } }, "foo") : string
>f83 : <T extends { [x: string]: { x: any; }; }, K extends keyof T>(obj: T, key: K) => T[K]["x"]
>{ foo: { x: "hello" } } : { foo: { x: string; }; }
>foo : { x: string; }
>{ x: "hello" } : { x: string; }
>x : string
>"hello" : "hello"
>"foo" : "foo"
let x2 = f83({ bar: { x: 42 } }, "bar"); // number
>x2 : number
>f83({ bar: { x: 42 } }, "bar") : number
>f83 : <T extends { [x: string]: { x: any; }; }, K extends keyof T>(obj: T, key: K) => T[K]["x"]
>{ bar: { x: 42 } } : { bar: { x: number; }; }
>bar : { x: number; }
>{ x: 42 } : { x: number; }
>x : number
>42 : 42
>"bar" : "bar"
}
class C1 {
>C1 : C1
x: number;
>x : number
get<K extends keyof this>(key: K) {
>get : <K extends keyof this>(key: K) => this[K]
>K : K
>key : K
>K : K
return this[key];
>this[key] : this[K]
>this : this
>key : K
}
set<K extends keyof this>(key: K, value: this[K]) {
>set : <K extends keyof this>(key: K, value: this[K]) => void
>K : K
>key : K
>K : K
>value : this[K]
>K : K
this[key] = value;
>this[key] = value : this[K]
>this[key] : this[K]
>this : this
>key : K
>value : this[K]
}
foo() {
>foo : () => void
let x1 = this.x; // number
>x1 : number
>this.x : number
>this : this
>x : number
let x2 = this["x"]; // number
>x2 : number
>this["x"] : number
>this : this
>"x" : "x"
let x3 = this.get("x"); // this["x"]
>x3 : this["x"]
>this.get("x") : this["x"]
>this.get : <K extends keyof this>(key: K) => this[K]
>this : this
>get : <K extends keyof this>(key: K) => this[K]
>"x" : "x"
let x4 = getProperty(this, "x"); // this["x"]
>x4 : this["x"]
>getProperty(this, "x") : this["x"]
>getProperty : <T, K extends keyof T>(obj: T, key: K) => T[K]
>this : this
>"x" : "x"
this.x = 42;
>this.x = 42 : 42
>this.x : number
>this : this
>x : number
>42 : 42
this["x"] = 42;
>this["x"] = 42 : 42
>this["x"] : number
>this : this
>"x" : "x"
>42 : 42
this.set("x", 42);
>this.set("x", 42) : void
>this.set : <K extends keyof this>(key: K, value: this[K]) => void
>this : this
>set : <K extends keyof this>(key: K, value: this[K]) => void
>"x" : "x"
>42 : 42
setProperty(this, "x", 42);
>setProperty(this, "x", 42) : void
>setProperty : <T, K extends keyof T>(obj: T, key: K, value: T[K]) => void
>this : this
>"x" : "x"
>42 : 42
}
}
// Repros from #12011
class Base {
@ -1202,10 +1441,10 @@ class Person extends Base {
>parts : number
}
getParts() {
>getParts : () => number
>getParts : () => this["parts"]
return this.get("parts")
>this.get("parts") : number
>this.get("parts") : this["parts"]
>this.get : <K extends keyof this>(prop: K) => this[K]
>this : this
>get : <K extends keyof this>(prop: K) => this[K]
@ -1230,10 +1469,10 @@ class OtherPerson {
>parts : number
}
getParts() {
>getParts : () => number
>getParts : () => this["parts"]
return getProperty(this, "parts")
>getProperty(this, "parts") : number
>getProperty(this, "parts") : this["parts"]
>getProperty : <T, K extends keyof T>(obj: T, key: K) => T[K]
>this : this
>"parts" : "parts"
@ -1587,3 +1826,52 @@ function f<K extends keyof R>(p: K) {
>p : K
>add : any
}
// Repro from #12651
type MethodDescriptor = {
>MethodDescriptor : MethodDescriptor
name: string;
>name : string
args: any[];
>args : any[]
returnValue: any;
>returnValue : any
}
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
>dispatchMethod : <M extends MethodDescriptor>(name: M["name"], args: M["args"]) => M["returnValue"]
>M : M
>MethodDescriptor : MethodDescriptor
>name : M["name"]
>M : M
>args : M["args"]
>M : M
>M : M
type SomeMethodDescriptor = {
>SomeMethodDescriptor : SomeMethodDescriptor
name: "someMethod";
>name : "someMethod"
args: [string, number];
>args : [string, number]
returnValue: string[];
>returnValue : string[]
}
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
>result : string[]
>dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]) : string[]
>dispatchMethod : <M extends MethodDescriptor>(name: M["name"], args: M["args"]) => M["returnValue"]
>SomeMethodDescriptor : SomeMethodDescriptor
>"someMethod" : "someMethod"
>["hello", 35] : [string, number]
>"hello" : "hello"
>35 : 35

View file

@ -1,9 +1,7 @@
tests/cases/compiler/keyofIsLiteralContexualType.ts(5,9): error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'.
Type '"a" | "b" | "c"' is not assignable to type 'keyof T'.
Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'.
Type '"c"' is not assignable to type 'keyof T'.
Type '"c"' is not assignable to type '"a" | "b"'.
Type '"c"' is not assignable to type 'keyof T'.
Type '"c"' is not assignable to type '"a" | "b"'.
tests/cases/compiler/keyofIsLiteralContexualType.ts(13,11): error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'.
@ -16,10 +14,8 @@ tests/cases/compiler/keyofIsLiteralContexualType.ts(13,11): error TS2339: Proper
~
!!! error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'.
!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type 'keyof T'.
!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'.
!!! error TS2322: Type '"c"' is not assignable to type 'keyof T'.
!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'.
!!! error TS2322: Type '"c"' is not assignable to type 'keyof T'.
!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'.
}
// Repro from #12455

View file

@ -26,9 +26,19 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(78,59): error TS2345: A
Object literal may only specify known properties, and 'z' does not exist in type 'Readonly<{ x: number; y: number; }>'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(84,58): error TS2345: Argument of type '{ x: number; y: number; z: number; }' is not assignable to parameter of type 'Partial<{ x: number; y: number; }>'.
Object literal may only specify known properties, and 'z' does not exist in type 'Partial<{ x: number; y: number; }>'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(106,15): error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
Types of property 'a' are incompatible.
Type 'undefined' is not assignable to type 'string'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(107,17): error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, "a" | "b">'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(124,12): error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
Types of property 'a' are incompatible.
Type 'undefined' is not assignable to type 'string'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(125,14): error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, "a" | "b">'.
==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (17 errors) ====
==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (21 errors) ====
interface Shape {
name: string;
@ -158,4 +168,59 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(84,58): error TS2345: A
~~~~
!!! error TS2345: Argument of type '{ x: number; y: number; z: number; }' is not assignable to parameter of type 'Partial<{ x: number; y: number; }>'.
!!! error TS2345: Object literal may only specify known properties, and 'z' does not exist in type 'Partial<{ x: number; y: number; }>'.
}
}
// Verify use of Pick<T, K> for setState functions (#12793)
interface Foo {
a: string;
b?: number;
}
function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>) {
for (let k in props) {
obj[k] = props[k];
}
}
let foo: Foo = { a: "hello", b: 42 };
setState(foo, { a: "test", b: 43 })
setState(foo, { a: "hi" });
setState(foo, { b: undefined });
setState(foo, { });
setState(foo, foo);
setState(foo, { a: undefined }); // Error
~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
!!! error TS2345: Types of property 'a' are incompatible.
!!! error TS2345: Type 'undefined' is not assignable to type 'string'.
setState(foo, { c: true }); // Error
~~~~~~~
!!! error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
!!! error TS2345: Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, "a" | "b">'.
class C<T> {
state: T;
setState<K extends keyof T>(props: Pick<T, K>) {
for (let k in props) {
this.state[k] = props[k];
}
}
}
let c = new C<Foo>();
c.setState({ a: "test", b: 43 });
c.setState({ a: "hi" });
c.setState({ b: undefined });
c.setState({ });
c.setState(foo);
c.setState({ a: undefined }); // Error
~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
!!! error TS2345: Types of property 'a' are incompatible.
!!! error TS2345: Type 'undefined' is not assignable to type 'string'.
c.setState({ c: true }); // Error
~~~~~~~
!!! error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
!!! error TS2345: Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, "a" | "b">'.

View file

@ -83,7 +83,48 @@ function f21() {
let x1 = objAndPartial({ x: 0, y: 0 }, { x: 1 });
let x2 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1 });
let x3 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
}
}
// Verify use of Pick<T, K> for setState functions (#12793)
interface Foo {
a: string;
b?: number;
}
function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>) {
for (let k in props) {
obj[k] = props[k];
}
}
let foo: Foo = { a: "hello", b: 42 };
setState(foo, { a: "test", b: 43 })
setState(foo, { a: "hi" });
setState(foo, { b: undefined });
setState(foo, { });
setState(foo, foo);
setState(foo, { a: undefined }); // Error
setState(foo, { c: true }); // Error
class C<T> {
state: T;
setState<K extends keyof T>(props: Pick<T, K>) {
for (let k in props) {
this.state[k] = props[k];
}
}
}
let c = new C<Foo>();
c.setState({ a: "test", b: 43 });
c.setState({ a: "hi" });
c.setState({ b: undefined });
c.setState({ });
c.setState(foo);
c.setState({ a: undefined }); // Error
c.setState({ c: true }); // Error
//// [mappedTypeErrors.js]
function f1(x) {
@ -124,6 +165,37 @@ function f21() {
var x2 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1 });
var x3 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
}
function setState(obj, props) {
for (var k in props) {
obj[k] = props[k];
}
}
var foo = { a: "hello", b: 42 };
setState(foo, { a: "test", b: 43 });
setState(foo, { a: "hi" });
setState(foo, { b: undefined });
setState(foo, {});
setState(foo, foo);
setState(foo, { a: undefined }); // Error
setState(foo, { c: true }); // Error
var C = (function () {
function C() {
}
C.prototype.setState = function (props) {
for (var k in props) {
this.state[k] = props[k];
}
};
return C;
}());
var c = new C();
c.setState({ a: "test", b: 43 });
c.setState({ a: "hi" });
c.setState({ b: undefined });
c.setState({});
c.setState(foo);
c.setState({ a: undefined }); // Error
c.setState({ c: true }); // Error
//// [mappedTypeErrors.d.ts]
@ -168,3 +240,14 @@ declare function objAndReadonly<T>(primary: T, secondary: Readonly<T>): T;
declare function objAndPartial<T>(primary: T, secondary: Partial<T>): T;
declare function f20(): void;
declare function f21(): void;
interface Foo {
a: string;
b?: number;
}
declare function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>): void;
declare let foo: Foo;
declare class C<T> {
state: T;
setState<K extends keyof T>(props: Pick<T, K>): void;
}
declare let c: C<Foo>;

View file

@ -1,145 +1,121 @@
//// [mappedTypeModifiers.ts]
type T = { a: number, b: string };
type TU = { a: number | undefined, b: string | undefined };
type TP = { a?: number, b?: string };
type TR = { readonly a: number, readonly b: string };
type TPR = { readonly a?: number, readonly b?: string };
// Validate they all have the same keys
var v00: "a" | "b";
var v00: keyof T;
var v00: keyof TU;
var v00: keyof TP;
var v00: keyof TR;
var v00: keyof TPR;
// Validate that non-isomorphic mapped types strip modifiers
var v01: T;
var v01: Pick<TR, keyof T>;
var v01: Pick<Readonly<T>, keyof T>;
var v01: { [P in keyof T]: T[P] };
var v01: Pick<T, keyof T>;
var v01: Pick<Pick<T, keyof T>, keyof T>;
// Validate that non-isomorphic mapped types strip modifiers
var v02: TU;
var v02: TP;
var v02: { [P in keyof T]?: T[P] };
var v02: Partial<T>;
var v02: Pick<TP, keyof T>;
var v02: Pick<TPR, keyof T>;
var v02: Pick<Partial<T>, keyof T>;
var v02: Pick<Partial<Readonly<T>>, keyof T>;
// Validate that isomorphic mapped types preserve optional modifier
var v03: TP;
var v03: Partial<T>;
var v03: TR;
var v03: { readonly [P in keyof T]: T[P] };
var v03: Readonly<T>;
var v03: Pick<TR, keyof T>;
// Validate that isomorphic mapped types preserve readonly modifier
var v04: TR;
var v04: Readonly<T>;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05: TPR;
var v05: Partial<TR>;
var v05: Readonly<TP>;
var v05: Partial<Readonly<T>>;
var v05: Readonly<Partial<T>>;
var v04: TPR;
var v04: { readonly [P in keyof T]?: T[P] };
var v04: Partial<TR>;
var v04: Readonly<TP>;
var v04: Partial<Readonly<T>>;
var v04: Readonly<Partial<T>>;
var v04: Pick<TPR, keyof T>;
type Boxified<T> = { [P in keyof T]: { x: T[P] } };
type B = { a: { x: number }, b: { x: string } };
type BU = { a: { x: number } | undefined, b: { x: string } | undefined };
type BP = { a?: { x: number }, b?: { x: string } };
type BR = { readonly a: { x: number }, readonly b: { x: string } };
type BPR = { readonly a?: { x: number }, readonly b?: { x: string } };
// Validate they all have the same keys
var b00: "a" | "b";
var b00: keyof B;
var b00: keyof BU;
var b00: keyof BP;
var b00: keyof BR;
var b00: keyof BPR;
// Validate that non-isomorphic mapped types strip modifiers
var b01: B;
var b01: Pick<BR, keyof B>;
var b01: Pick<Readonly<BR>, keyof B>;
var b01: { [P in keyof B]: B[P] };
var b01: Pick<B, keyof B>;
var b01: Pick<Pick<B, keyof B>, keyof B>;
// Validate that non-isomorphic mapped types strip modifiers
var b02: BU;
var b02: BP;
var b02: { [P in keyof B]?: B[P] };
var b02: Partial<B>;
var b02: Pick<BP, keyof B>;
var b02: Pick<BPR, keyof B>;
var b02: Pick<Partial<B>, keyof B>;
var b02: Pick<Partial<Readonly<B>>, keyof B>;
// Validate that isomorphic mapped types preserve optional modifier
var b03: BP;
var b03: Partial<B>;
var b03: BR;
var b03: { readonly [P in keyof B]: B[P] };
var b03: Readonly<B>;
var b03: Pick<BR, keyof B>;
// Validate that isomorphic mapped types preserve readonly modifier
var b04: BR;
var b04: Readonly<B>;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05: BPR;
var b05: Partial<BR>;
var b05: Readonly<BP>;
var b05: Partial<Readonly<B>>;
var b05: Readonly<Partial<B>>;
var b04: BPR;
var b04: { readonly [P in keyof B]?: B[P] };
var b04: Partial<BR>;
var b04: Readonly<BP>;
var b04: Partial<Readonly<B>>;
var b04: Readonly<Partial<B>>;
var b04: Pick<BPR, keyof B>;
//// [mappedTypeModifiers.js]
// Validate they all have the same keys
var v00;
var v00;
var v00;
var v00;
var v00;
var v00;
// Validate that non-isomorphic mapped types strip modifiers
var v01;
var v01;
var v01;
// Validate that non-isomorphic mapped types strip modifiers
var v01;
var v02;
var v02;
var v02;
var v02;
var v02;
// Validate that isomorphic mapped types preserve optional modifier
var v03;
var v03;
// Validate that isomorphic mapped types preserve readonly modifier
var v03;
var v03;
var v04;
var v04;
var v04;
var v04;
var v04;
var v04;
var v04;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05;
var v05;
var v05;
var v05;
var v05;
// Validate they all have the same keys
var b00;
var b00;
var b00;
var b00;
var b00;
var b00;
// Validate that non-isomorphic mapped types strip modifiers
var b01;
var b01;
var b01;
// Validate that non-isomorphic mapped types strip modifiers
var b01;
var b02;
var b02;
var b02;
var b02;
var b02;
// Validate that isomorphic mapped types preserve optional modifier
var b03;
var b03;
// Validate that isomorphic mapped types preserve readonly modifier
var b03;
var b03;
var b04;
var b04;
var b04;
var b04;
var b04;
var b04;
var b04;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05;
var b05;
var b05;
var b05;
var b05;

View file

@ -5,309 +5,309 @@ type T = { a: number, b: string };
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 1, 10))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 1, 21))
type TU = { a: number | undefined, b: string | undefined };
>TU : Symbol(TU, Decl(mappedTypeModifiers.ts, 1, 34))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 2, 11))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 2, 34))
type TP = { a?: number, b?: string };
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 2, 59))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 3, 11))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 3, 23))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 1, 34))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 2, 11))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 2, 23))
type TR = { readonly a: number, readonly b: string };
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 3, 37))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 4, 11))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 4, 31))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 2, 37))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 3, 11))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 3, 31))
type TPR = { readonly a?: number, readonly b?: string };
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 4, 53))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 5, 12))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 5, 33))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 3, 53))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 4, 12))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 4, 33))
// Validate they all have the same keys
var v00: "a" | "b";
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3), Decl(mappedTypeModifiers.ts, 11, 3), Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3))
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 6, 3), Decl(mappedTypeModifiers.ts, 7, 3), Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3))
var v00: keyof T;
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3), Decl(mappedTypeModifiers.ts, 11, 3), Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3))
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 6, 3), Decl(mappedTypeModifiers.ts, 7, 3), Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v00: keyof TU;
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3), Decl(mappedTypeModifiers.ts, 11, 3), Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3))
>TU : Symbol(TU, Decl(mappedTypeModifiers.ts, 1, 34))
var v00: keyof TP;
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3), Decl(mappedTypeModifiers.ts, 11, 3), Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 2, 59))
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 6, 3), Decl(mappedTypeModifiers.ts, 7, 3), Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 1, 34))
var v00: keyof TR;
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3), Decl(mappedTypeModifiers.ts, 11, 3), Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 3, 37))
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 6, 3), Decl(mappedTypeModifiers.ts, 7, 3), Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 2, 37))
var v00: keyof TPR;
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3), Decl(mappedTypeModifiers.ts, 11, 3), Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 4, 53))
>v00 : Symbol(v00, Decl(mappedTypeModifiers.ts, 6, 3), Decl(mappedTypeModifiers.ts, 7, 3), Decl(mappedTypeModifiers.ts, 8, 3), Decl(mappedTypeModifiers.ts, 9, 3), Decl(mappedTypeModifiers.ts, 10, 3))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 3, 53))
// Validate that non-isomorphic mapped types strip modifiers
var v01: T;
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 16, 3), Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3))
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3), Decl(mappedTypeModifiers.ts, 14, 3), Decl(mappedTypeModifiers.ts, 15, 3))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v01: Pick<TR, keyof T>;
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 16, 3), Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3))
var v01: { [P in keyof T]: T[P] };
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3), Decl(mappedTypeModifiers.ts, 14, 3), Decl(mappedTypeModifiers.ts, 15, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 13, 12))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 13, 12))
var v01: Pick<T, keyof T>;
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3), Decl(mappedTypeModifiers.ts, 14, 3), Decl(mappedTypeModifiers.ts, 15, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 3, 37))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v01: Pick<Readonly<T>, keyof T>;
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 16, 3), Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3))
var v01: Pick<Pick<T, keyof T>, keyof T>;
>v01 : Symbol(v01, Decl(mappedTypeModifiers.ts, 12, 3), Decl(mappedTypeModifiers.ts, 13, 3), Decl(mappedTypeModifiers.ts, 14, 3), Decl(mappedTypeModifiers.ts, 15, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
// Validate that non-isomorphic mapped types strip modifiers
var v02: TU;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 21, 3), Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>TU : Symbol(TU, Decl(mappedTypeModifiers.ts, 1, 34))
var v02: TP;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3), Decl(mappedTypeModifiers.ts, 19, 3), Decl(mappedTypeModifiers.ts, 20, 3))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 1, 34))
var v02: { [P in keyof T]?: T[P] };
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3), Decl(mappedTypeModifiers.ts, 19, 3), Decl(mappedTypeModifiers.ts, 20, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 18, 12))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 18, 12))
var v02: Partial<T>;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3), Decl(mappedTypeModifiers.ts, 19, 3), Decl(mappedTypeModifiers.ts, 20, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v02: Pick<TP, keyof T>;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 21, 3), Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 17, 3), Decl(mappedTypeModifiers.ts, 18, 3), Decl(mappedTypeModifiers.ts, 19, 3), Decl(mappedTypeModifiers.ts, 20, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 2, 59))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 1, 34))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v02: Pick<TPR, keyof T>;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 21, 3), Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
var v03: TR;
>v03 : Symbol(v03, Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 2, 37))
var v03: { readonly [P in keyof T]: T[P] };
>v03 : Symbol(v03, Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 23, 21))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 23, 21))
var v03: Readonly<T>;
>v03 : Symbol(v03, Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v03: Pick<TR, keyof T>;
>v03 : Symbol(v03, Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 4, 53))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 2, 37))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v02: Pick<Partial<T>, keyof T>;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 21, 3), Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
var v04: TPR;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 3, 53))
var v04: { readonly [P in keyof T]?: T[P] };
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 28, 21))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 28, 21))
var v04: Partial<TR>;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 2, 37))
var v04: Readonly<TP>;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 1, 34))
var v04: Partial<Readonly<T>>;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v04: Readonly<Partial<T>>;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v04: Pick<TPR, keyof T>;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 27, 3), Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3), Decl(mappedTypeModifiers.ts, 30, 3), Decl(mappedTypeModifiers.ts, 31, 3), Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v02: Pick<Partial<Readonly<T>>, keyof T>;
>v02 : Symbol(v02, Decl(mappedTypeModifiers.ts, 21, 3), Decl(mappedTypeModifiers.ts, 22, 3), Decl(mappedTypeModifiers.ts, 23, 3), Decl(mappedTypeModifiers.ts, 24, 3), Decl(mappedTypeModifiers.ts, 25, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
// Validate that isomorphic mapped types preserve optional modifier
var v03: TP;
>v03 : Symbol(v03, Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 2, 59))
var v03: Partial<T>;
>v03 : Symbol(v03, Decl(mappedTypeModifiers.ts, 28, 3), Decl(mappedTypeModifiers.ts, 29, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
// Validate that isomorphic mapped types preserve readonly modifier
var v04: TR;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 3, 37))
var v04: Readonly<T>;
>v04 : Symbol(v04, Decl(mappedTypeModifiers.ts, 32, 3), Decl(mappedTypeModifiers.ts, 33, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05: TPR;
>v05 : Symbol(v05, Decl(mappedTypeModifiers.ts, 36, 3), Decl(mappedTypeModifiers.ts, 37, 3), Decl(mappedTypeModifiers.ts, 38, 3), Decl(mappedTypeModifiers.ts, 39, 3), Decl(mappedTypeModifiers.ts, 40, 3))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 4, 53))
var v05: Partial<TR>;
>v05 : Symbol(v05, Decl(mappedTypeModifiers.ts, 36, 3), Decl(mappedTypeModifiers.ts, 37, 3), Decl(mappedTypeModifiers.ts, 38, 3), Decl(mappedTypeModifiers.ts, 39, 3), Decl(mappedTypeModifiers.ts, 40, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>TR : Symbol(TR, Decl(mappedTypeModifiers.ts, 3, 37))
var v05: Readonly<TP>;
>v05 : Symbol(v05, Decl(mappedTypeModifiers.ts, 36, 3), Decl(mappedTypeModifiers.ts, 37, 3), Decl(mappedTypeModifiers.ts, 38, 3), Decl(mappedTypeModifiers.ts, 39, 3), Decl(mappedTypeModifiers.ts, 40, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>TP : Symbol(TP, Decl(mappedTypeModifiers.ts, 2, 59))
var v05: Partial<Readonly<T>>;
>v05 : Symbol(v05, Decl(mappedTypeModifiers.ts, 36, 3), Decl(mappedTypeModifiers.ts, 37, 3), Decl(mappedTypeModifiers.ts, 38, 3), Decl(mappedTypeModifiers.ts, 39, 3), Decl(mappedTypeModifiers.ts, 40, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
var v05: Readonly<Partial<T>>;
>v05 : Symbol(v05, Decl(mappedTypeModifiers.ts, 36, 3), Decl(mappedTypeModifiers.ts, 37, 3), Decl(mappedTypeModifiers.ts, 38, 3), Decl(mappedTypeModifiers.ts, 39, 3), Decl(mappedTypeModifiers.ts, 40, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>TPR : Symbol(TPR, Decl(mappedTypeModifiers.ts, 3, 53))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 0, 0))
type Boxified<T> = { [P in keyof T]: { x: T[P] } };
>Boxified : Symbol(Boxified, Decl(mappedTypeModifiers.ts, 40, 30))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 42, 14))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 42, 22))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 42, 14))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 42, 38))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 42, 14))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 42, 22))
>Boxified : Symbol(Boxified, Decl(mappedTypeModifiers.ts, 33, 28))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 35, 14))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 35, 22))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 35, 14))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 35, 38))
>T : Symbol(T, Decl(mappedTypeModifiers.ts, 35, 14))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 35, 22))
type B = { a: { x: number }, b: { x: string } };
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 44, 10))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 44, 15))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 44, 28))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 44, 33))
type BU = { a: { x: number } | undefined, b: { x: string } | undefined };
>BU : Symbol(BU, Decl(mappedTypeModifiers.ts, 44, 48))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 45, 11))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 45, 16))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 45, 41))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 45, 46))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 37, 10))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 37, 15))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 37, 28))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 37, 33))
type BP = { a?: { x: number }, b?: { x: string } };
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 45, 73))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 46, 11))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 46, 17))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 46, 30))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 46, 36))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 37, 48))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 38, 11))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 38, 17))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 38, 30))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 38, 36))
type BR = { readonly a: { x: number }, readonly b: { x: string } };
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 46, 51))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 47, 11))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 47, 25))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 47, 38))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 47, 52))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 38, 51))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 39, 11))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 39, 25))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 39, 38))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 39, 52))
type BPR = { readonly a?: { x: number }, readonly b?: { x: string } };
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 47, 67))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 48, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 48, 27))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 48, 40))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 48, 55))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 39, 67))
>a : Symbol(a, Decl(mappedTypeModifiers.ts, 40, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 40, 27))
>b : Symbol(b, Decl(mappedTypeModifiers.ts, 40, 40))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 40, 55))
// Validate they all have the same keys
var b00: "a" | "b";
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 51, 3), Decl(mappedTypeModifiers.ts, 52, 3), Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 42, 3), Decl(mappedTypeModifiers.ts, 43, 3), Decl(mappedTypeModifiers.ts, 44, 3), Decl(mappedTypeModifiers.ts, 45, 3), Decl(mappedTypeModifiers.ts, 46, 3))
var b00: keyof B;
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 51, 3), Decl(mappedTypeModifiers.ts, 52, 3), Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
var b00: keyof BU;
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 51, 3), Decl(mappedTypeModifiers.ts, 52, 3), Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>BU : Symbol(BU, Decl(mappedTypeModifiers.ts, 44, 48))
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 42, 3), Decl(mappedTypeModifiers.ts, 43, 3), Decl(mappedTypeModifiers.ts, 44, 3), Decl(mappedTypeModifiers.ts, 45, 3), Decl(mappedTypeModifiers.ts, 46, 3))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b00: keyof BP;
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 51, 3), Decl(mappedTypeModifiers.ts, 52, 3), Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 45, 73))
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 42, 3), Decl(mappedTypeModifiers.ts, 43, 3), Decl(mappedTypeModifiers.ts, 44, 3), Decl(mappedTypeModifiers.ts, 45, 3), Decl(mappedTypeModifiers.ts, 46, 3))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 37, 48))
var b00: keyof BR;
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 51, 3), Decl(mappedTypeModifiers.ts, 52, 3), Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 46, 51))
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 42, 3), Decl(mappedTypeModifiers.ts, 43, 3), Decl(mappedTypeModifiers.ts, 44, 3), Decl(mappedTypeModifiers.ts, 45, 3), Decl(mappedTypeModifiers.ts, 46, 3))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 38, 51))
var b00: keyof BPR;
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 51, 3), Decl(mappedTypeModifiers.ts, 52, 3), Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 47, 67))
>b00 : Symbol(b00, Decl(mappedTypeModifiers.ts, 42, 3), Decl(mappedTypeModifiers.ts, 43, 3), Decl(mappedTypeModifiers.ts, 44, 3), Decl(mappedTypeModifiers.ts, 45, 3), Decl(mappedTypeModifiers.ts, 46, 3))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 39, 67))
// Validate that non-isomorphic mapped types strip modifiers
var b01: B;
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 48, 3), Decl(mappedTypeModifiers.ts, 49, 3), Decl(mappedTypeModifiers.ts, 50, 3), Decl(mappedTypeModifiers.ts, 51, 3))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b01: Pick<BR, keyof B>;
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
var b01: { [P in keyof B]: B[P] };
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 48, 3), Decl(mappedTypeModifiers.ts, 49, 3), Decl(mappedTypeModifiers.ts, 50, 3), Decl(mappedTypeModifiers.ts, 51, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 49, 12))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 49, 12))
var b01: Pick<B, keyof B>;
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 48, 3), Decl(mappedTypeModifiers.ts, 49, 3), Decl(mappedTypeModifiers.ts, 50, 3), Decl(mappedTypeModifiers.ts, 51, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 46, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b01: Pick<Readonly<BR>, keyof B>;
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
var b01: Pick<Pick<B, keyof B>, keyof B>;
>b01 : Symbol(b01, Decl(mappedTypeModifiers.ts, 48, 3), Decl(mappedTypeModifiers.ts, 49, 3), Decl(mappedTypeModifiers.ts, 50, 3), Decl(mappedTypeModifiers.ts, 51, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 46, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
// Validate that non-isomorphic mapped types strip modifiers
var b02: BU;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3))
>BU : Symbol(BU, Decl(mappedTypeModifiers.ts, 44, 48))
var b02: BP;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 37, 48))
var b02: { [P in keyof B]?: B[P] };
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 54, 12))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 54, 12))
var b02: Partial<B>;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b02: Pick<BP, keyof B>;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3))
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 53, 3), Decl(mappedTypeModifiers.ts, 54, 3), Decl(mappedTypeModifiers.ts, 55, 3), Decl(mappedTypeModifiers.ts, 56, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 45, 73))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 37, 48))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b02: Pick<BPR, keyof B>;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3))
var b03: BR;
>b03 : Symbol(b03, Decl(mappedTypeModifiers.ts, 58, 3), Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 38, 51))
var b03: { readonly [P in keyof B]: B[P] };
>b03 : Symbol(b03, Decl(mappedTypeModifiers.ts, 58, 3), Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 59, 21))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 59, 21))
var b03: Readonly<B>;
>b03 : Symbol(b03, Decl(mappedTypeModifiers.ts, 58, 3), Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b03: Pick<BR, keyof B>;
>b03 : Symbol(b03, Decl(mappedTypeModifiers.ts, 58, 3), Decl(mappedTypeModifiers.ts, 59, 3), Decl(mappedTypeModifiers.ts, 60, 3), Decl(mappedTypeModifiers.ts, 61, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 47, 67))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 38, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b02: Pick<Partial<B>, keyof B>;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3))
var b04: BPR;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 39, 67))
var b04: { readonly [P in keyof B]?: B[P] };
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 64, 21))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 64, 21))
var b04: Partial<BR>;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 38, 51))
var b04: Readonly<BP>;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 37, 48))
var b04: Partial<Readonly<B>>;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b04: Readonly<Partial<B>>;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))
var b04: Pick<BPR, keyof B>;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 63, 3), Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3), Decl(mappedTypeModifiers.ts, 69, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
var b02: Pick<Partial<Readonly<B>>, keyof B>;
>b02 : Symbol(b02, Decl(mappedTypeModifiers.ts, 64, 3), Decl(mappedTypeModifiers.ts, 65, 3), Decl(mappedTypeModifiers.ts, 66, 3), Decl(mappedTypeModifiers.ts, 67, 3), Decl(mappedTypeModifiers.ts, 68, 3))
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
// Validate that isomorphic mapped types preserve optional modifier
var b03: BP;
>b03 : Symbol(b03, Decl(mappedTypeModifiers.ts, 71, 3), Decl(mappedTypeModifiers.ts, 72, 3))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 45, 73))
var b03: Partial<B>;
>b03 : Symbol(b03, Decl(mappedTypeModifiers.ts, 71, 3), Decl(mappedTypeModifiers.ts, 72, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
// Validate that isomorphic mapped types preserve readonly modifier
var b04: BR;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 75, 3), Decl(mappedTypeModifiers.ts, 76, 3))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 46, 51))
var b04: Readonly<B>;
>b04 : Symbol(b04, Decl(mappedTypeModifiers.ts, 75, 3), Decl(mappedTypeModifiers.ts, 76, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05: BPR;
>b05 : Symbol(b05, Decl(mappedTypeModifiers.ts, 79, 3), Decl(mappedTypeModifiers.ts, 80, 3), Decl(mappedTypeModifiers.ts, 81, 3), Decl(mappedTypeModifiers.ts, 82, 3), Decl(mappedTypeModifiers.ts, 83, 3))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 47, 67))
var b05: Partial<BR>;
>b05 : Symbol(b05, Decl(mappedTypeModifiers.ts, 79, 3), Decl(mappedTypeModifiers.ts, 80, 3), Decl(mappedTypeModifiers.ts, 81, 3), Decl(mappedTypeModifiers.ts, 82, 3), Decl(mappedTypeModifiers.ts, 83, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>BR : Symbol(BR, Decl(mappedTypeModifiers.ts, 46, 51))
var b05: Readonly<BP>;
>b05 : Symbol(b05, Decl(mappedTypeModifiers.ts, 79, 3), Decl(mappedTypeModifiers.ts, 80, 3), Decl(mappedTypeModifiers.ts, 81, 3), Decl(mappedTypeModifiers.ts, 82, 3), Decl(mappedTypeModifiers.ts, 83, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>BP : Symbol(BP, Decl(mappedTypeModifiers.ts, 45, 73))
var b05: Partial<Readonly<B>>;
>b05 : Symbol(b05, Decl(mappedTypeModifiers.ts, 79, 3), Decl(mappedTypeModifiers.ts, 80, 3), Decl(mappedTypeModifiers.ts, 81, 3), Decl(mappedTypeModifiers.ts, 82, 3), Decl(mappedTypeModifiers.ts, 83, 3))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
var b05: Readonly<Partial<B>>;
>b05 : Symbol(b05, Decl(mappedTypeModifiers.ts, 79, 3), Decl(mappedTypeModifiers.ts, 80, 3), Decl(mappedTypeModifiers.ts, 81, 3), Decl(mappedTypeModifiers.ts, 82, 3), Decl(mappedTypeModifiers.ts, 83, 3))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 42, 51))
>BPR : Symbol(BPR, Decl(mappedTypeModifiers.ts, 39, 67))
>B : Symbol(B, Decl(mappedTypeModifiers.ts, 35, 51))

View file

@ -5,11 +5,6 @@ type T = { a: number, b: string };
>a : number
>b : string
type TU = { a: number | undefined, b: string | undefined };
>TU : TU
>a : number | undefined
>b : string | undefined
type TP = { a?: number, b?: string };
>TP : TP
>a : number | undefined
@ -25,7 +20,6 @@ type TPR = { readonly a?: number, readonly b?: string };
>a : number | undefined
>b : string | undefined
// Validate they all have the same keys
var v00: "a" | "b";
>v00 : "a" | "b"
@ -33,10 +27,6 @@ var v00: keyof T;
>v00 : "a" | "b"
>T : T
var v00: keyof TU;
>v00 : "a" | "b"
>TU : TU
var v00: keyof TP;
>v00 : "a" | "b"
>TP : TP
@ -49,103 +39,114 @@ var v00: keyof TPR;
>v00 : "a" | "b"
>TPR : TPR
// Validate that non-isomorphic mapped types strip modifiers
var v01: T;
>v01 : T
>T : T
var v01: Pick<TR, keyof T>;
var v01: { [P in keyof T]: T[P] };
>v01 : T
>Pick : Pick<T, K>
>TR : TR
>P : P
>T : T
>T : T
>P : P
var v01: Pick<Readonly<T>, keyof T>;
var v01: Pick<T, keyof T>;
>v01 : T
>Pick : Pick<T, K>
>Readonly : Readonly<T>
>T : T
>T : T
// Validate that non-isomorphic mapped types strip modifiers
var v02: TU;
>v02 : TU
>TU : TU
var v01: Pick<Pick<T, keyof T>, keyof T>;
>v01 : T
>Pick : Pick<T, K>
>Pick : Pick<T, K>
>T : T
>T : T
>T : T
var v02: TP;
>v02 : TP
>TP : TP
var v02: { [P in keyof T]?: T[P] };
>v02 : TP
>P : P
>T : T
>T : T
>P : P
var v02: Partial<T>;
>v02 : TP
>Partial : Partial<T>
>T : T
var v02: Pick<TP, keyof T>;
>v02 : TU
>v02 : TP
>Pick : Pick<T, K>
>TP : TP
>T : T
var v02: Pick<TPR, keyof T>;
>v02 : TU
>Pick : Pick<T, K>
>TPR : TPR
>T : T
var v02: Pick<Partial<T>, keyof T>;
>v02 : TU
>Pick : Pick<T, K>
>Partial : Partial<T>
>T : T
>T : T
var v02: Pick<Partial<Readonly<T>>, keyof T>;
>v02 : TU
>Pick : Pick<T, K>
>Partial : Partial<T>
>Readonly : Readonly<T>
>T : T
>T : T
// Validate that isomorphic mapped types preserve optional modifier
var v03: TP;
>v03 : TP
>TP : TP
var v03: Partial<T>;
>v03 : TP
>Partial : Partial<T>
>T : T
// Validate that isomorphic mapped types preserve readonly modifier
var v04: TR;
>v04 : TR
var v03: TR;
>v03 : TR
>TR : TR
var v04: Readonly<T>;
>v04 : TR
var v03: { readonly [P in keyof T]: T[P] };
>v03 : TR
>P : P
>T : T
>T : T
>P : P
var v03: Readonly<T>;
>v03 : TR
>Readonly : Readonly<T>
>T : T
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05: TPR;
>v05 : TPR
var v03: Pick<TR, keyof T>;
>v03 : TR
>Pick : Pick<T, K>
>TR : TR
>T : T
var v04: TPR;
>v04 : TPR
>TPR : TPR
var v05: Partial<TR>;
>v05 : TPR
var v04: { readonly [P in keyof T]?: T[P] };
>v04 : TPR
>P : P
>T : T
>T : T
>P : P
var v04: Partial<TR>;
>v04 : TPR
>Partial : Partial<T>
>TR : TR
var v05: Readonly<TP>;
>v05 : TPR
var v04: Readonly<TP>;
>v04 : TPR
>Readonly : Readonly<T>
>TP : TP
var v05: Partial<Readonly<T>>;
>v05 : TPR
var v04: Partial<Readonly<T>>;
>v04 : TPR
>Partial : Partial<T>
>Readonly : Readonly<T>
>T : T
var v05: Readonly<Partial<T>>;
>v05 : TPR
var v04: Readonly<Partial<T>>;
>v04 : TPR
>Readonly : Readonly<T>
>Partial : Partial<T>
>T : T
var v04: Pick<TPR, keyof T>;
>v04 : TPR
>Pick : Pick<T, K>
>TPR : TPR
>T : T
type Boxified<T> = { [P in keyof T]: { x: T[P] } };
>Boxified : Boxified<T>
>T : T
@ -162,13 +163,6 @@ type B = { a: { x: number }, b: { x: string } };
>b : { x: string; }
>x : string
type BU = { a: { x: number } | undefined, b: { x: string } | undefined };
>BU : BU
>a : { x: number; } | undefined
>x : number
>b : { x: string; } | undefined
>x : string
type BP = { a?: { x: number }, b?: { x: string } };
>BP : BP
>a : { x: number; } | undefined
@ -190,7 +184,6 @@ type BPR = { readonly a?: { x: number }, readonly b?: { x: string } };
>b : { x: string; } | undefined
>x : string
// Validate they all have the same keys
var b00: "a" | "b";
>b00 : "a" | "b"
@ -198,10 +191,6 @@ var b00: keyof B;
>b00 : "a" | "b"
>B : B
var b00: keyof BU;
>b00 : "a" | "b"
>BU : BU
var b00: keyof BP;
>b00 : "a" | "b"
>BP : BP
@ -214,100 +203,111 @@ var b00: keyof BPR;
>b00 : "a" | "b"
>BPR : BPR
// Validate that non-isomorphic mapped types strip modifiers
var b01: B;
>b01 : B
>B : B
var b01: Pick<BR, keyof B>;
var b01: { [P in keyof B]: B[P] };
>b01 : B
>P : P
>B : B
>B : B
>P : P
var b01: Pick<B, keyof B>;
>b01 : B
>Pick : Pick<T, K>
>BR : BR
>B : B
>B : B
var b01: Pick<Readonly<BR>, keyof B>;
var b01: Pick<Pick<B, keyof B>, keyof B>;
>b01 : B
>Pick : Pick<T, K>
>Readonly : Readonly<T>
>BR : BR
>Pick : Pick<T, K>
>B : B
>B : B
>B : B
// Validate that non-isomorphic mapped types strip modifiers
var b02: BU;
>b02 : BU
>BU : BU
var b02: BP;
>b02 : BP
>BP : BP
var b02: { [P in keyof B]?: B[P] };
>b02 : BP
>P : P
>B : B
>B : B
>P : P
var b02: Partial<B>;
>b02 : BP
>Partial : Partial<T>
>B : B
var b02: Pick<BP, keyof B>;
>b02 : BU
>b02 : BP
>Pick : Pick<T, K>
>BP : BP
>B : B
var b02: Pick<BPR, keyof B>;
>b02 : BU
var b03: BR;
>b03 : BR
>BR : BR
var b03: { readonly [P in keyof B]: B[P] };
>b03 : BR
>P : P
>B : B
>B : B
>P : P
var b03: Readonly<B>;
>b03 : BR
>Readonly : Readonly<T>
>B : B
var b03: Pick<BR, keyof B>;
>b03 : BR
>Pick : Pick<T, K>
>BR : BR
>B : B
var b04: BPR;
>b04 : BPR
>BPR : BPR
var b04: { readonly [P in keyof B]?: B[P] };
>b04 : BPR
>P : P
>B : B
>B : B
>P : P
var b04: Partial<BR>;
>b04 : BPR
>Partial : Partial<T>
>BR : BR
var b04: Readonly<BP>;
>b04 : BPR
>Readonly : Readonly<T>
>BP : BP
var b04: Partial<Readonly<B>>;
>b04 : BPR
>Partial : Partial<T>
>Readonly : Readonly<T>
>B : B
var b04: Readonly<Partial<B>>;
>b04 : BPR
>Readonly : Readonly<T>
>Partial : Partial<T>
>B : B
var b04: Pick<BPR, keyof B>;
>b04 : BPR
>Pick : Pick<T, K>
>BPR : BPR
>B : B
var b02: Pick<Partial<B>, keyof B>;
>b02 : BU
>Pick : Pick<T, K>
>Partial : Partial<T>
>B : B
>B : B
var b02: Pick<Partial<Readonly<B>>, keyof B>;
>b02 : BU
>Pick : Pick<T, K>
>Partial : Partial<T>
>Readonly : Readonly<T>
>B : B
>B : B
// Validate that isomorphic mapped types preserve optional modifier
var b03: BP;
>b03 : BP
>BP : BP
var b03: Partial<B>;
>b03 : BP
>Partial : Partial<T>
>B : B
// Validate that isomorphic mapped types preserve readonly modifier
var b04: BR;
>b04 : BR
>BR : BR
var b04: Readonly<B>;
>b04 : BR
>Readonly : Readonly<T>
>B : B
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05: BPR;
>b05 : BPR
>BPR : BPR
var b05: Partial<BR>;
>b05 : BPR
>Partial : Partial<T>
>BR : BR
var b05: Readonly<BP>;
>b05 : BPR
>Readonly : Readonly<T>
>BP : BP
var b05: Partial<Readonly<B>>;
>b05 : BPR
>Partial : Partial<T>
>Readonly : Readonly<T>
>B : B
var b05: Readonly<Partial<B>>;
>b05 : BPR
>Readonly : Readonly<T>
>Partial : Partial<T>
>B : B

View file

@ -0,0 +1,31 @@
// @declaration: true
type T1 = {
x: T1["x"]; // Error
};
type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
y: number;
}
declare let x2: T2<"x">;
let x2x = x2.x;
interface T3<T extends T3<T>> {
x: T["x"]; // Error
}
interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
}
class C1 {
x: C1["x"]; // Error
}
class C2 {
x: this["y"]; // Error
y: this["z"]; // Error
z: this["x"]; // Error
}

View file

@ -250,6 +250,53 @@ function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[
let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
}
function f80<T extends { a: { x: any } }>(obj: T) {
let a1 = obj.a; // { x: any }
let a2 = obj['a']; // { x: any }
let a3 = obj['a'] as T['a']; // T["a"]
let x1 = obj.a.x; // any
let x2 = obj['a']['x']; // any
let x3 = obj['a']['x'] as T['a']['x']; // T["a"]["x"]
}
function f81<T extends { a: { x: any } }>(obj: T) {
return obj['a']['x'] as T['a']['x'];
}
function f82() {
let x1 = f81({ a: { x: "hello" } }); // string
let x2 = f81({ a: { x: 42 } }); // number
}
function f83<T extends { [x: string]: { x: any } }, K extends keyof T>(obj: T, key: K) {
return obj[key]['x'] as T[K]['x'];
}
function f84() {
let x1 = f83({ foo: { x: "hello" } }, "foo"); // string
let x2 = f83({ bar: { x: 42 } }, "bar"); // number
}
class C1 {
x: number;
get<K extends keyof this>(key: K) {
return this[key];
}
set<K extends keyof this>(key: K, value: this[K]) {
this[key] = value;
}
foo() {
let x1 = this.x; // number
let x2 = this["x"]; // number
let x3 = this.get("x"); // this["x"]
let x4 = getProperty(this, "x"); // this["x"]
this.x = 42;
this["x"] = 42;
this.set("x", 42);
setProperty(this, "x", 42);
}
}
// Repros from #12011
class Base {
@ -365,4 +412,22 @@ interface R {
function f<K extends keyof R>(p: K) {
let a: any;
a[p].add; // any
}
}
// Repro from #12651
type MethodDescriptor = {
name: string;
args: any[];
returnValue: any;
}
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
type SomeMethodDescriptor = {
name: "someMethod";
args: [string, number];
returnValue: string[];
}
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);

View file

@ -84,4 +84,44 @@ function f21() {
let x1 = objAndPartial({ x: 0, y: 0 }, { x: 1 });
let x2 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1 });
let x3 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
}
}
// Verify use of Pick<T, K> for setState functions (#12793)
interface Foo {
a: string;
b?: number;
}
function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>) {
for (let k in props) {
obj[k] = props[k];
}
}
let foo: Foo = { a: "hello", b: 42 };
setState(foo, { a: "test", b: 43 })
setState(foo, { a: "hi" });
setState(foo, { b: undefined });
setState(foo, { });
setState(foo, foo);
setState(foo, { a: undefined }); // Error
setState(foo, { c: true }); // Error
class C<T> {
state: T;
setState<K extends keyof T>(props: Pick<T, K>) {
for (let k in props) {
this.state[k] = props[k];
}
}
}
let c = new C<Foo>();
c.setState({ a: "test", b: 43 });
c.setState({ a: "hi" });
c.setState({ b: undefined });
c.setState({ });
c.setState(foo);
c.setState({ a: undefined }); // Error
c.setState({ c: true }); // Error

View file

@ -1,85 +1,71 @@
// @strictNullChecks: true
type T = { a: number, b: string };
type TU = { a: number | undefined, b: string | undefined };
type TP = { a?: number, b?: string };
type TR = { readonly a: number, readonly b: string };
type TPR = { readonly a?: number, readonly b?: string };
// Validate they all have the same keys
var v00: "a" | "b";
var v00: keyof T;
var v00: keyof TU;
var v00: keyof TP;
var v00: keyof TR;
var v00: keyof TPR;
// Validate that non-isomorphic mapped types strip modifiers
var v01: T;
var v01: Pick<TR, keyof T>;
var v01: Pick<Readonly<T>, keyof T>;
var v01: { [P in keyof T]: T[P] };
var v01: Pick<T, keyof T>;
var v01: Pick<Pick<T, keyof T>, keyof T>;
// Validate that non-isomorphic mapped types strip modifiers
var v02: TU;
var v02: TP;
var v02: { [P in keyof T]?: T[P] };
var v02: Partial<T>;
var v02: Pick<TP, keyof T>;
var v02: Pick<TPR, keyof T>;
var v02: Pick<Partial<T>, keyof T>;
var v02: Pick<Partial<Readonly<T>>, keyof T>;
// Validate that isomorphic mapped types preserve optional modifier
var v03: TP;
var v03: Partial<T>;
var v03: TR;
var v03: { readonly [P in keyof T]: T[P] };
var v03: Readonly<T>;
var v03: Pick<TR, keyof T>;
// Validate that isomorphic mapped types preserve readonly modifier
var v04: TR;
var v04: Readonly<T>;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05: TPR;
var v05: Partial<TR>;
var v05: Readonly<TP>;
var v05: Partial<Readonly<T>>;
var v05: Readonly<Partial<T>>;
var v04: TPR;
var v04: { readonly [P in keyof T]?: T[P] };
var v04: Partial<TR>;
var v04: Readonly<TP>;
var v04: Partial<Readonly<T>>;
var v04: Readonly<Partial<T>>;
var v04: Pick<TPR, keyof T>;
type Boxified<T> = { [P in keyof T]: { x: T[P] } };
type B = { a: { x: number }, b: { x: string } };
type BU = { a: { x: number } | undefined, b: { x: string } | undefined };
type BP = { a?: { x: number }, b?: { x: string } };
type BR = { readonly a: { x: number }, readonly b: { x: string } };
type BPR = { readonly a?: { x: number }, readonly b?: { x: string } };
// Validate they all have the same keys
var b00: "a" | "b";
var b00: keyof B;
var b00: keyof BU;
var b00: keyof BP;
var b00: keyof BR;
var b00: keyof BPR;
// Validate that non-isomorphic mapped types strip modifiers
var b01: B;
var b01: Pick<BR, keyof B>;
var b01: Pick<Readonly<BR>, keyof B>;
var b01: { [P in keyof B]: B[P] };
var b01: Pick<B, keyof B>;
var b01: Pick<Pick<B, keyof B>, keyof B>;
// Validate that non-isomorphic mapped types strip modifiers
var b02: BU;
var b02: BP;
var b02: { [P in keyof B]?: B[P] };
var b02: Partial<B>;
var b02: Pick<BP, keyof B>;
var b02: Pick<BPR, keyof B>;
var b02: Pick<Partial<B>, keyof B>;
var b02: Pick<Partial<Readonly<B>>, keyof B>;
// Validate that isomorphic mapped types preserve optional modifier
var b03: BP;
var b03: Partial<B>;
var b03: BR;
var b03: { readonly [P in keyof B]: B[P] };
var b03: Readonly<B>;
var b03: Pick<BR, keyof B>;
// Validate that isomorphic mapped types preserve readonly modifier
var b04: BR;
var b04: Readonly<B>;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05: BPR;
var b05: Partial<BR>;
var b05: Readonly<BP>;
var b05: Partial<Readonly<B>>;
var b05: Readonly<Partial<B>>;
var b04: BPR;
var b04: { readonly [P in keyof B]?: B[P] };
var b04: Partial<BR>;
var b04: Readonly<BP>;
var b04: Partial<Readonly<B>>;
var b04: Readonly<Partial<B>>;
var b04: Pick<BPR, keyof B>;