I'm expecting that typescript will throw an error because I'm passing the wrong number of elements in EntryPoints, but it doesn't happen.
function createContext<T>(defaultValue: T): T[] {
return [defaultValue]
}
interface EntryPoints {
parentSelector: string;
}
interface SomeType {
entryPoints: EntryPoints[];
}
const defaultData = {
entryPoints: [{
parentSelector: '',
foo: 1 // <-- expecting error here
}]
}
createContext<SomeType>(defaultData)
Same code without generic works as expected
function createContext<T>(defaultValue: T): T[] {
return [defaultValue]
}
interface EntryPoints {
parentSelector: string;
}
interface SomeType {
entryPoints: EntryPoints[];
}
const defaultData: SomeType = {
entryPoints: [{
parentSelector: '',
foo: 1 // <-- throwing error here
}]
}
createContext(defaultData)