MCPcopy Index your code
hub / github.com/plotly/dash / getPropType

Function getPropType

dash/extract-meta.js:323–417  ·  view source on GitHub ↗
(propType, propObj, parentType = null)

Source from the content-addressed store, hash-verified

321 };
322
323 const getPropType = (propType, propObj, parentType = null) => {
324 // Types can get namespace prefixes or not.
325 let name = checker.typeToString(propType).replace(/^React\./, '');
326 let value, elements;
327 const raw = name;
328
329 const newParentType = (parentType || []).concat(raw)
330
331 if (propType.isUnion()) {
332 if (isUnionLiteral(propType)) {
333 return {...getEnum(propType), raw};
334 } else if (raw.includes('|')) {
335 return {...getUnion(propType, propObj, newParentType), raw};
336 }
337 }
338
339 name = getPropTypeName(name);
340
341 // Shapes & array support.
342 if (!PRIMITIVES.concat('enum', 'func', 'union').includes(name)) {
343 if (
344 // Excluding object with arrays in the raw.
345 (name.includes('[]') && name.endsWith("]")) ||
346 name.includes('Array')
347 ) {
348 name = 'arrayOf';
349 const replaced = raw.replace('[]', '');
350 if (unionSupport.includes(replaced)) {
351 // Simple types are easier.
352 value = {
353 name: getPropTypeName(replaced),
354 raw: replaced
355 };
356 } else {
357 // Complex types get the type parameter (Array<type>)
358 const [nodeType] = checker.getTypeArguments(propType);
359
360 if (nodeType) {
361 value = getPropType(
362 nodeType, propObj, newParentType,
363 );
364 } else {
365 // Not sure, might be unsupported here.
366 name = 'array';
367 }
368 }
369 } else if (
370 name === 'tuple' ||
371 (name.startsWith('[') && name.endsWith(']'))
372 ) {
373 name = 'tuple';
374 elements = propType.resolvedTypeArguments.map(
375 t => getPropType(t, propObj, newParentType)
376 );
377 } else if (
378 BANNED_TYPES.includes(name) ||
379 (parentType && parentType.includes(name))
380 ) {

Callers 2

getUnionFunction · 0.70
getPropsFunction · 0.70

Calls 6

isUnionLiteralFunction · 0.85
getEnumFunction · 0.85
getUnionFunction · 0.85
getPropTypeNameFunction · 0.70
getPropsFunction · 0.70
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…