我的库的直接接口由
捕获index.d.ts
目前是从
自动生成的index.ts
在我的项目的package.json文件中,typings / types属性指向这个index.d.ts文件,这是我的理解,它应该如何。到目前为止一切都很好。
但是,我还想从index.d.ts中导出更多类型,这些类型目前尚未在index.d.ts中表示。
例如,我在
中有一些手动创建的类型foo.d.ts
bar.d.ts
我希望这些在index.d.ts中表达。
我认为可行的唯一方法是将foo.d.ts / bar.d.ts类型导入index.d.ts,然后从该文件中导出它们。
然而,我遇到了麻烦!
以下是我的尝试:
// index.ts
import {IBar} from '../bar.d.ts'
import {IFoo} from '../foo.d.ts'
// ... do some stuff with index.ts yadda yadda
export type IBar = IBar; // doesn't seem to work
export interface IFoo = IFoo; // doesn't seem to work
这可能吗?我该怎么做?
答案 0 :(得分:3)
如果您不需要使用它们,可以直接导出它们。
/**
* Returns a progression that goes over the same range with the given step.
*/
public infix fun BigDecimalProgression.step(step: BigDecimal): BigDecimalProgression {
if (step <= java.math.BigDecimal.ZERO) throw IllegalArgumentException("Step must be positive, was: $step.")
return BigDecimalProgression.fromClosedRange(first, last, if (this.step > java.math.BigDecimal.ZERO) step else -step)
}
/**
* A progression of values of type `BigDecimal`.
*/
public open class BigDecimalProgression
internal constructor
(
start: BigDecimal,
endInclusive: BigDecimal,
step: BigDecimal
) : Iterable<BigDecimal> {
init {
if (step == BigDecimal.ZERO) throw kotlin.IllegalArgumentException("Step must be non-zero")
}
/**
* The first element in the progression.
*/
public val first: BigDecimal = start
/**
* The last element in the progression.
*/
public val last: BigDecimal = getProgressionLastElement(start, endInclusive, step)
/**
* The step of the progression.
*/
public val step: BigDecimal = step
override fun iterator(): BigDecimalIterator = BigDecimalProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > BigDecimal.ZERO) first > last else first < last
override fun equals(other: Any?): Boolean =
other is BigDecimalProgression && (isEmpty() && other.isEmpty() ||
first == other.first && last == other.last && step == other.step)
override fun hashCode(): Int =
if (isEmpty()) -1 else (31 * (31 * first.hashCode() + last.hashCode()) + step.hashCode())
override fun toString(): String = if (step > BigDecimal.ZERO) "$first..$last step $step" else "$first downTo $last step ${-step}"
companion object {
/**
* Creates BigDecimalProgression within the specified bounds of a closed range.
* The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step].
* In order to go backwards the [step] must be negative.
*/
public fun fromClosedRange(rangeStart: BigDecimal, rangeEnd: BigDecimal, step: BigDecimal): BigDecimalProgression = BigDecimalProgression(rangeStart, rangeEnd, step)
}
}
fun getProgressionLastElement(start: BigDecimal, end: BigDecimal, step: BigDecimal): BigDecimal {
if (step > BigDecimal.ZERO) {
return start + BigDecimal(((end - start) / step).toInt()) * step
} else if (step < BigDecimal.ZERO) {
return start - BigDecimal(((start - end) / -step).toInt()) * -step
} else {
throw kotlin.IllegalArgumentException("Step is zero.")
}
}
/** An iterator over a sequence of values of type `BigDecimal`. */
public abstract class BigDecimalIterator : Iterator<BigDecimal> {
override final fun next() = nextBigDecimal()
/** Returns the next value in the sequence without boxing. */
public abstract fun nextBigDecimal(): BigDecimal
}
/**
* An iterator over a progression of values of type `BigDecimal`.
* @property step the number by which the value is incremented on each step.
*/
internal class BigDecimalProgressionIterator(first: BigDecimal, last: BigDecimal, val step: BigDecimal) : BigDecimalIterator() {
private val finalElement = last
private var hasNext: Boolean = if (step > BigDecimal.ZERO) first <= last else first >= last
private var next = if (hasNext) first else finalElement
override fun hasNext(): Boolean = hasNext
override fun nextBigDecimal(): BigDecimal {
val value = next
if (value >= finalElement) {
if (!hasNext) throw kotlin.NoSuchElementException()
hasNext = false
}
else {
next += step
}
return value
}
}
或者,如果您只需要导出其中一些,则可以使用。
export * from '../foo/bar';
或者,如果您想在导出期间重命名它们,您可以执行以下操作:
export { IFoo, IBar} from '../foo/bar';
您可以在MDN文档here中详细了解它们。
答案 1 :(得分:2)
您可以尝试:
s:hidden
答案 2 :(得分:2)
我认为其他答案会奏效。如果你确实需要在文件中使用IFoo和IBar,那么这就是:
batch_row = "<tr><td><input form='receiving-form' name='batch_no' class='form-control show_disabled' type='text' value='"+$('#last-batch-no').val()+"' id='batch_no-"+batch_ctr+"' /></td><td><input name='batch_date' form='receiving-form' class='form-control show_disabled' type='text' value='"+currentDate+"' id='batch_cur_date-"+batch_ctr+"'/></td><td><input form='receiving-form' name='batch_qty' id='qty-"+batch_ctr+"' class='form-control show_disabled' type='text' value='"+$('#receiving-box-table tbody>tr').length+"' /></td><td></td></tr>";
这很有效,但对于&#34;导出导入&#34;有点尴尬。语法。