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.
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
β― Playground Link
Workbench Repro
π Actual behavior
TS4.5.4 is happy to compile my code, but ts4.6.x complains on access
anonymousUserorusers: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.