TS2538: Type 'unique symbol' cannot be used as an index type - tsc

I have this:
const symbols = {
typeMap: Symbol('type.map')
}
interface LangMap {
[key: string]: string | true,
golang: string,
typescript: string,
java: string,
swift: string
}
export const setTypeMap = function(v: LangMap) : LangMap{
v[symbols.typeMap] = true;
return v;
};
I get this error:
TS2538: Type 'unique symbol' cannot be used as an index type.
Does anyone know what that error is about? I am on tsc version 3.1.6.

My poor workaround :
const bar: Record<any, string> = {};
const FOO = Symbol('foo');
// eslint-disable-next-line #typescript-eslint/no-explicit-any
bar[FOO as any] = 'sad';

Related

I'm new to Motoko and this code is giving me errors

actor {
type Post = {
id : Int;
creater : String;
};
stable var Posts : [Post] = [];
func addPost(id : Int, creater : String) : () {
Posts.push(id, creater);
};
};
How can I push an object in that mutable array that is defined as Posts?
It seems that you are looking for Array.append, however as it is deprecated, you should use Buffers with preupgrade and postupgrade instead of the following:
import Array "mo:base/Array";
actor {
type Post = {
id : Int;
creator : Text;
};
stable var Posts = Array.init<Post>(1, { id = 0; creator = "" });
func addPost(id : Int, creator : Text) : () {
let NewPosts = Array.init<Post>(1, { id; creator });
Posts := Array.thaw(Array.append(Array.freeze(Posts), Array.freeze(NewPosts)));
};
};

React-native typescript error: Type 'Generator<any, any, unknown>' is missing the following properties from type

I have a function to return an object named UploadToGetId that I defined myself and it worked in runtime, but I got an error in compile time
Type 'Generator<any, any, unknown>' is missing the following properties from type 'UploadToGetID': imageId, imageThumbId
This is my code:
type UploadToGetID = {
imageId: string | undefined;
imageThumbId: string | undefined;
};
function* uploadImageOrVideoToGetId(
image: Image | undefined,
imageThumb: ImageThumb | undefined,
): UploadToGetID {
const uploadId: UploadToGetID = {
imageId: undefined,
imageThumbId: undefined,
};
try {
if (image) {
const token = yield Helper.getDataStored(JWT_KEY);
let newImage: ImageResizerResponse = yield call(
ImageResizer.createResizedImage,
imageThumb!.url!,
5000,
5000,
'JPEG',
100,
);
let file = newImage.uri;
if (Platform.OS === 'android') {
file = newImage.uri.replace('file://', '');
}
...
} catch (error) {
Alert.alert('Upload image fail! ' + error);
return uploadId;
}
}
Help me if you know how to fix it

Alternative of ctx.updateSubTypes Telgraf 4

That end point was removed with new version of telgraf
https://github.com/telegraf/telegraf/releases/tag/v4.0.0#:~:text=ctx.updateSubTypes
How we can detect the message type with new API
this is the old ctx retrun
This is an alternative usage to ctx.updatesubtypes AKA getting message type in telegraf 3.
bot.use((ctx, next) => {
console.log(`Message Type is: ${getMessageType(ctx.message)}`);
// Message Type is: STICKER or Message Type is: TEXT
});
const getMessageType = (message) => {
var keys = Object.keys(message);
var messageType = keys.pop();
console.log(messageType);
return messageType.toUpperCase();
};
source is: https://stackoverflow.com/a/58052712/10694425
A good alternative to using ctx.updatesubtypes in 4.6.0 is:
bot.use((ctx, next) => {
let message_type = "";
let keys = Object.keys(ctx.message);
if (keys.includes("text")) {
message_type = "text";
} else if (keys.includes("sticker")) {
message_type = "sticker";
} else if (keys.includes("photo")) {
message_type = "photo";
}
console.log(`Message Type is: ${message_type}`);
next();
});

Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed cannot remove console error after using the input check box

I'm trying to bind the data from api which is written in .net core with angular api using ng for i getting the value properly but when i use the check input field my console is full on unstoppable errors
I have tried many examples from stackoverflow non them worked for me
export class UsermanagementComponent {
userDetailsList: any = [];
public userList: any= [];
departmentuser: any = {};
public searchTxt:any;
isActive: boolean = false;
checkuserstatus: boolean;
constructor(private router: Router, private http: HttpClient, private
toastr: ToastrService, private appComponent: AppComponent) {
this.userList
}
private jwtHelper: JwtHelperService = new JwtHelperService();
ngOnInit() {
this.appComponent.startSpinner();
this.getuser();
;
}
edituser(userList: any) {
localStorage.setItem("userList", JSON.stringify(userList));
console.log(userList);
this.router.navigate(["/landingpage/edituser"], userList);
}
lockUnlockUser(userList: any) {
console.log(userList);
this.http.post(environment.apiUrl + "Account/LockUserAccount", userList,
{
}).subscribe(data => {
this.appComponent.stopSpinner();
this.router.navigate(["/landingpage/usermanagement"]);
this.userList = data;
this.checkuserstatus = this.userList.lockoutEnabled;
console.log(this.checkuserstatus);
if (this.checkuserstatus == true) {
let toast = this.toastr.success(MessageVariable.UserLocked);
alert(toast);
} else if (this.checkuserstatus == false) {
let toast = this.toastr.info(MessageVariable.UserUnLocked);
alert(toast);
}
}, (err) => {
this.toastr.error(MessageVariable.ErrorMsg);
});
}
getuser() {
this.appComponent.startSpinner();
var userId = localStorage.getItem('userid');
console.log(userId);
this.http.get(environment.apiUrl + "Account/GetUser", {
}).subscribe(data => {
this.appComponent.stopSpinner();
this.userList = data;
console.log(this.userList);
}, (err) => {
this.toastr.error(MessageVariable.ErrorMsg);
});
}
}
UsermanagementComponent.html:22 ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
at

Wrong queryString when building navigation plan in aurelia-router

We're using aurelia-open-id-connect in our project and after successful login the redirect is removing the querystring from the url. I've debugged my way through the aurelia-router and I think I found something. Should'nt the queryString in redirectInstruction be used there?
export const buildRedirectPlan = (instruction: NavigationInstruction) => {
const config = instruction.config;
const router = instruction.router;
return router
._createNavigationInstruction(config.redirect)
.then(redirectInstruction => {
const params: Record<string, any> = {};
const originalInstructionParams = instruction.params;
const redirectInstructionParams = redirectInstruction.params;
for (let key in redirectInstructionParams) {
// If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }
let val = redirectInstructionParams[key];
if (typeof val === 'string' && val[0] === ':') {
val = val.slice(1);
// And if that param is found on the original instruction then use it
if (val in originalInstructionParams) {
params[key] = originalInstructionParams[val];
}
} else {
params[key] = redirectInstructionParams[key];
}
}
let redirectLocation = router.generate(redirectInstruction.config, params, instruction.options);
// Special handling for child routes
for (let key in originalInstructionParams) {
redirectLocation = redirectLocation.replace(`:${key}`, originalInstructionParams[key]);
}
let queryString = instruction.queryString;
// use redirectInstruction.queryString instead?
if (queryString) {
redirectLocation += '?' + queryString;
}
return Promise.resolve(new Redirect(redirectLocation));
});
};