TypeScript/tests/cases/compiler/expandoFunctionContextualTypesJs.ts
Wesley Wigham f1370ecd54
Allow special assignments to have a contextual type of their declared type if present (#26802)
* Allow special assignments to have a contextual type of their declared type if present

* Expand change to cover all js special assignments

* Remove extraneous line
2018-09-04 15:58:18 -07:00

58 lines
990 B
TypeScript

// @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: input.js
/** @typedef {{ color: "red" | "blue" }} MyComponentProps */
/**
* @template P
* @typedef {{ (): any; defaultProps?: Partial<P> }} StatelessComponent */
/**
* @type {StatelessComponent<MyComponentProps>}
*/
const MyComponent = () => /* @type {any} */(null);
MyComponent.defaultProps = {
color: "red"
};
const MyComponent2 = () => null;
/**
* @type {MyComponentProps}
*/
MyComponent2.defaultProps = {
color: "red"
}
/**
* @type {StatelessComponent<MyComponentProps>}
*/
const check = MyComponent2;
/**
*
* @param {{ props: MyComponentProps }} p
*/
function expectLiteral(p) {}
function foo() {
/**
* @type {MyComponentProps}
*/
this.props = { color: "red" };
expectLiteral(this);
}
/**
* @type {MyComponentProps}
*/
module.exports = {
color: "red"
}
expectLiteral({ props: module.exports });