TypeScript nightmares (solved?)
data.id;
(<any>data).id; //access id like if data has no type
function onEnter(el: HTMLElement, done: gsap.Callback) {}
In tsconfig.json
{
"compilerOptions": {
"lib": ["es6", "es2017", "es2017.string", "dom"],
}
}
<script lang="ts">
const timer: Ref<ReturnType<typeof setTimeout> | null> = ref(null);
</script>
interface ISomeDynamicObject {
[key: number]: SomeOtherArrayType[];
}
// or
const someObject: Record<number, SomeOtherArrayTyp[]> = {};
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
? Acc[number]
: Enumerate<N, [...Acc, Acc['length']]>;
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
class SingleCard {
suit: 'clubs' | 'diamonds' | 'hearts' | 'spades';
rank: IntRange<1, 13>;
}
interface INutritionalValues {
calcium: 0;
iron: 0;
}
interface IField {
id: keyof INutritionalValues; // must be calcium or iron as defined in INutritionalValues
}
// @ts-ignore