You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceNodeConfig{appName: string;port: number;}classNodeAppBuilder{privateconfiguration: NodeConfig={appName: 'NodeApp',port: 3000};config(config: Partial<NodeConfig>){typeNodeConfigKey=keyofNodeConfig;for(constkeyofObject.keys(config)asNodeConfigKey[]){constupdateValue=config[key];if(updateValue===undefined){continue;}this.configuration[key]=updateValue;}returnthis;}}// `Partial<NodeConfig>`` allows us to provide only a part of the// NodeConfig interface.newNodeAppBuilder().config({appName: 'ToDoApp'});
Type 'string | number' is not assignable to type'string & number'.
Type 'string' is not assignable to type'string & number'.
Type 'string' is not assignable to type'number'.
I would submit pull request but my typescript journey is just beginning; nut shell either typescript bug or from 3.5.1 strictness on this is tighter. But for me both types are string | number| so 🤷♂
The text was updated successfully, but these errors were encountered:
Hi, I'll respond and try to fix the code on 7th Sept.
But, what's happening here is most likely caused by TypeScripts' 3.5Fixes to unsound writes to indexed access types.
It's not really an access issue but assign issue. Since simply accessing the property by key works fine.
Any ideas why accessing and assigning gives different types?
const x = this.configuration[key]; // string | number
this.configuration[key] /* string & number */ = <value>; // TS 3.5
this.configuration[key] /* never */ = <value>; // TS 3.6
Partial Example: error from
3.5.1
playground example
https://www.typescriptlang.org/play/?ts=3.3.3#code/JYOwLgpgTgZghgYwgAgHIHsAmEDC6QzADmyA3gLABQyycADnanALYQBcyAzmFKEQNxUaddFDAcQAV2YAjaIMoBfKlQQAbOJ05osEAIIMAQpOBrsUMkOR1eANziRkCfISKSoD4Pg4ZseAsTIALyW1DS0DEysHADkvvoMMQA0VsKi4sgAzAAMuVaKClbOAUQAFMWuHAAKcGLAcGoAPPH+rgB8AJSh4chgAJ50KC0uxADSEH3ByADWE+gwOn4jAiphNDCiyOX43DMTyPPIAPIyAFYQCGAAdLN9nNslXZqLuMvjfQDaALpdFGvhxV2kjomAcEAAag1JCgQhViB9bl9Cv8aMAFqVgaDIJC1NDgkEQpIQNhCCAIJhfqkek58GBQNCFNTkMpKFSaGAABbAThXOFuDx0-AIiZfKaYsE46FUllUqAQMDuEC9LmcRnMqgsoA
I would submit pull request but my typescript journey is just beginning; nut shell either typescript bug or from 3.5.1 strictness on this is tighter. But for me both types are
string | number|
so 🤷♂The text was updated successfully, but these errors were encountered: