By : Antonio Gutiérrez
Date : January 12 2021, 08:33 AM
|
around this issue In case you think this question is different enough from the other one I linked to: That definition means the class constructor is also a callable function with no arguments that returns a string when called without new. You can't use a ES2015-or- later class and adhere to the specification, since it would need to throw a TypeError upon being called without new. Instead you can return a function that detects being called with new, with extra properties added to implement static methods. code :
interface FunctionalPartOfDateConstructor {
new(): Date;
new(value: number): Date;
new(value: string): Date;
new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date;
(): string;
}
const funcPart = function(valueOrYear?: number | string, month?: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date | string {
if (typeof new.target === 'undefined') {
// called as function
return Date();
}
if (typeof valueOrYear === 'undefined') {
// called as constructor with no arguments
return new Date();
}
if (typeof valueOrYear === 'string') {
// called as constructor with string value argument
return new Date(valueOrYear);
}
if (typeof month === 'undefined') {
// called as constructor with number value argument
return new Date(valueOrYear);
}
// called as constructor with year, month, date, etc arguments:
return new Date(valueOrYear, month, date, hours, minutes, seconds, ms);
} as FunctionalPartOfDateConstructor;
const myDateConstructor: DateConstructor = Object.assign(funcPart, {
prototype: Date.prototype,
parse(s: string) {
return Date.parse(s);
},
UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number) {
return Date.UTC(year, month, date, hours, minutes, seconds, ms);
},
now() {
return Date.now();
}
})
Share :
|
What's the difference between "declare class" and "interface" in TypeScript
By : mojtaba
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , interface is for when you simply want to describe the shape of an object. There's no code generation, ever, for interfaces -- they're solely an artifact in the type system. You'll see no difference in the code generation for a class depending on whether or not it has an implements clause. declare class is for when you want to describe an existing class (usually a TypeScript class, but not always) that is going to be externally present (for example, you have two .ts files that compile to two .js files and both are included via script tags in a webpage). If you inherit from a class using extends (regardless of whether the base type was a declare class or a regular class) the compiler is going to generate all the code to hook up the prototype chain and forwarding constructors and what not.
|
Method "DefaultAdapter" with signature "" on interface "org.bluez.Manager" doesn't exist i
By : shixing leo
Date : March 29 2020, 07:55 AM
I hope this helps you . I had the same issue with org.bluez.Manager There is also org.freedesktop.DBus.ObjectManager. This should get you those objects (from https://github.com/Douglas6/blueplayer/blob/master/blueplayer.py): code :
import dbus
SERVICE_NAME = "org.bluez"
OBJECT_IFACE = "org.freedesktop.DBus.ObjectManager"
ADAPTER_IFACE = SERVICE_NAME + ".Adapter1"
DEVICE_IFACE = SERVICE_NAME + ".Device1"
PROPERTIES_IFACE = "org.freedesktop.DBus.Properties"
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.freedesktop.DBus.ObjectManager")
objects = manager.GetManagedObjects()
for path, ifaces in objects.iteritems():
adapter = ifaces.get(ADAPTER_IFACE)
if adapter is None:
continue
obj = bus.get_object(SERVICE_NAME, path)
adapter = dbus.Interface(obj, ADAPTER_IFACE)
|
How to see property available values when "string literal type" is used inside Interface in Typescript?
By : Kumar Bhimsen
Date : March 29 2020, 07:55 AM
hope this fix your issue I will answer my own question: If you guys are wondering why this occurs, it is by design as @pushkin mentioned below, but if you want to see the available values that you can pass, simple you have to press CONTROL + SPACE to see available values while assigning the value.
|
Typescript: No index signature with a parameter of type 'string' was found on type '{ "A": string; }
By : user2870087
Date : March 29 2020, 07:55 AM
Hope that helps You can fix the errors by validating your input, which is something you should do regardless of course. The following typechecks correctly, via type guarding validations code :
const DNATranscriber = {
G: 'C',
C: 'G',
T: 'A',
A: 'U'
};
export default class Transcriptor {
toRna(sequence: string) {
const sequenceArray = [...sequence];
if (!isValidSequence(sequenceArray)) {
throw Error('invalid sequence');
}
const transcribedRNA = sequenceArray.map(codon => DNATranscriber[codon]);
return transcribedRNA;
}
}
function isValidSequence(codons: string[]): codons is Array<keyof typeof DNATranscriber> {
return codons.every(isValidCodon);
}
function isValidCodon(value: string): value is keyof typeof DNATranscriber {
return value in DNATranscriber;
}
enum DNATranscriber {
G = 'C',
C = 'G',
T = 'A',
A = 'U'
}
export default function toRna(sequence: string) {
const sequenceArray = [...sequence];
if (!isValidSequence(sequenceArray)) {
throw Error('invalid sequence');
}
const transcribedRNA = sequenceArray.map(codon => DNATranscriber[codon]);
return transcribedRNA;
}
function isValidSequence(values: string[]): codons is Array<keyof typeof DNATranscriber> {
return values.every(isValidCodon);
}
function isValidCodon(value: string): value is keyof typeof DNATranscriber {
return value in DNATranscriber;
}
enum DNATranscriber {
G = 'C',
C = 'G',
T = 'A',
A = 'U'
}
export default function toRna(sequence: string) {
const sequenceArray = [...sequence];
validateSequence(sequenceArray);
const transcribedRNA = sequenceArray.map(codon => DNATranscriber[codon]);
return transcribedRNA;
}
function validateSequence(values: string[]): asserts codons is Array<keyof typeof DNATranscriber> {
if (!values.every(isValidCodon)) {
throw Error('invalid sequence');
}
}
function isValidCodon(value: string): value is keyof typeof DNATranscriber {
return value in DNATranscriber;
}
|
How to resolve "Invalid signature. Expected signature base string" in OAuth 1.0
By : Tinker
Date : March 29 2020, 07:55 AM
hope this fix your issue you can take a look here, it was asked about a week ago. Response:
|
|
|
Related Posts :
|