Answer the question
In order to leave comments, you need to log in
Is it possible to do without type casting when assigning a string to a variable with a literal type?
Good day.
There is a type that describes a small object. By design, it should be a constant.
declare type KDFEncryptOptions = {
kdf: 'scrypt',
n: 8192,
};
somefunction(encryptOptions as KDFEncryptOptions);
Answer the question
In order to leave comments, you need to log in
try like this. we can give a ride
/**
* @template {string} T
* @param {T} encryptOptions
*/
function somefunction(encryptOptions)
So you need the encryptOptions type to be KDFEncryptOptions -
declare interface KDFEncryptOptions {
kdf: 'scrypt';
n: 8192;
}
function somefunction(encryptOptions: KDFEncryptOptions) {
console.log('!!!');
}
let a: KDFEncryptOptions = { kdf: 'scrypt', n: 8192 };
somefunction(a);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question