Skip to content

ts4.6.1-rc regression: Property ... does not exist on type 'Partial<MyStorage>[K]'Β #47890

@HolgerJeromin

Description

@HolgerJeromin

Bug Report

πŸ”Ž Search Terms

partial, generics

πŸ•— Version & Regression Information

Tested with nuget package 4.6.0 and 4.6.1-rc and "nightly" on playground with is labeled v4.6.0-dev.20220116

  • This changed between versions 4.5.4 and 4.6.0

⏯ Playground Link

function __getStoredValue<K extends keyof Grid.Storage>(
    key: K
): Grid.Storage[K]['anonymousUser'] | undefined {
    let user = 'admin';

    let storageForKey = {
        anonymousUser: [1],
        users: {
            admin: [2]
        }
    } as Partial<Grid.Storage>[K];

    if (!storageForKey) {
        return undefined;
    }

    if (!user) {
        return storageForKey.anonymousUser;  // <--
    } else {
        if (storageForKey.users) {  // <--
            return storageForKey.users[user]; // <--
        }
        return undefined;
    }
}
namespace Grid {
    export interface Storage {
        columnWidths: StorageItem<number[]>;
    }
    export interface StorageItem<V> {
        /** value for anon */
        anonymousUser: V;
        /** value for each user */
        users: Record<string, V>;
    }
}
const result = __getStoredValue('columnWidths');
console.log(result);

Workbench Repro

πŸ™ Actual behavior

TS4.5.4 is happy to compile my code, but ts4.6.x complains on access anonymousUser or users:

Property 'anonymousUser' does not exist on type 'Partial[K]'.
Property 'users' does not exist on type 'Partial[K]'.
Property 'users' does not exist on type 'Partial[K]'.

πŸ™‚ Expected behavior

Should still compile as the property exists on the type.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions