In id?
Wat is de ?
voor?
Antwoord 1, Autoriteit 100%
Het is om de parameter te markeren als optioneel .
- typescript handbook https://www.typrescriptlang.org/ Documenten / Handboek / 2 / Functions.html # Optionele parameters
- typescript diepe duik https://basarat.gitbook.io/typescript / Type-systeem / functies # Optionele parameters
Antwoord 2, Autoriteit 14%
Dit is om de -variabele van optioneel type te maken. Anders verklaarde variabelen toont “undefined ” als deze variabele niet wordt gebruikt.
export interface ISearchResult {
title: string;
listTitle:string;
entityName?: string,
lookupName?:string,
lookupId?:string
}
Antwoord 3, Autoriteit 11%
parameter?: type
is een steno voor parameter: type | undefined
Antwoord 4, Autoriteit 2%
De ?
In de parameters is om een optionele parameter aan te duiden. De typescript-compiler vereist niet dat deze parameter wordt ingevuld. Zie het onderstaande code voor meer informatie:
// baz: number | undefined means: the second argument baz can be a number or undefined
// = undefined, is default parameter syntax,
// if the parameter is not filled in it will default to undefined
// Although default JS behaviour is to set every non filled in argument to undefined
// we need this default argument so that the typescript compiler
// doesn't require the second argument to be filled in
function fn1 (bar: string, baz: number | undefined = undefined) {
// do stuff
}
// All the above code can be simplified using the ? operator after the parameter
// In other words fn1 and fn2 are equivalent in behaviour
function fn2 (bar: string, baz?: number) {
// do stuff
}
fn2('foo', 3); // works
fn2('foo'); // works
fn2();
// Compile time error: Expected 1-2 arguments, but got 0
// An argument for 'bar' was not provided.
fn1('foo', 3); // works
fn1('foo'); // works
fn1();
// Compile time error: Expected 1-2 arguments, but got 0
// An argument for 'bar' was not provided.